Code file analysis method and device, computer equipment and storage medium

By generating an abstract code tree and parsing the call chain of code nodes, the problem of unavailable code file packages during application upgrades was solved, enabling accurate location and repair during the upgrade process and preventing application crashes.

CN120994200APending Publication Date: 2025-11-21TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410624293.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-20
Publication Date
2025-11-21

AI Technical Summary

Technical Problem

During application upgrades, the inability to accurately locate unavailable code files can render these files unusable, leading to application crashes.

Method used

By generating an abstract code tree, traversing code nodes, determining node types, and calling a parsing function to parse the call chain when conditions are met, the results are stored in an assignment dictionary, ultimately obtaining a call chain list of the code file. This is used to accurately locate unusable code file packages during upgrade development.

Benefits of technology

It enables accurate location of unusable code file packages during application upgrades, timely repair, and prevention of application crashes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120994200A_ABST
    Figure CN120994200A_ABST
Patent Text Reader

Abstract

The invention relates to a code file analysis method and device, computer equipment and a storage medium. The method relates to the cloud technology and comprises the steps of obtaining a code file to be analyzed, generating an abstract code tree based on the code file, traversing each code node in the abstract code tree, and determining the node type of each current traversal node for the current traversal node. And when determining that the current traversal node meets an analytic function execution condition according to the node type, calling an analytic function by the calling node, carrying out call chain analysis on the current traversal node to obtain a call chain analysis result of the current traversal node, and storing the call chain analysis result of the current traversal node to an assignment dictionary. And when all code nodes in the abstract code tree are traversed, obtaining a call chain list corresponding to the code file according to the assignment dictionary. By the adoption of the method, the code file packages can be effectively analyzed, the dependent calling relation between the different code file packages is obtained, and the unavailable code file packages are accurately positioned based on the calling chain list.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computers, and in particular to a code file parsing method and device, a computer device, a computer readable storage medium, and a computer program product. BACKGROUND

[0002] With the development of computer technology and the popularization of various application programs or systems, in order to meet the actual needs of application programs or systems during application, the application programs or systems need to be upgraded.

[0003] Traditionally, when upgrading an application program, a new version of an installation package usually needs to be developed according to actual needs. Since an application program usually involves multiple different functions and a large number of code files, there is usually a dependency relationship between code file packages corresponding to different functions in the installation package and the code file packages call interfaces with each other during the development of the upgrade. If the installation package needs to be upgraded, the compatibility between different code file packages may change, resulting in the unavailability of a code file package corresponding to a function or a code file package dependent on a function.

[0004] However, in the traditional upgrade development mode, the unavailable code file package cannot be accurately located, and the code file package cannot be corrected in time, and the problem of application program crash caused by the unavailability of the code file package still exists. SUMMARY

[0005] Therefore, it is necessary to provide a code file parsing method, device, computer device, computer readable storage medium, and computer program product that can effectively parse code file packages, obtain the dependency and calling relationship between different code file packages, accurately locate the unavailable code file package, repair the code file package in time, and avoid application program crash.

[0006] In a first aspect, the present application provides a code file parsing method, comprising:

[0007] obtaining a code file to be parsed, and generating an abstract code tree based on the code file;

[0008] traversing each code node in the abstract code tree, determining the node type of each current traversal node for each current traversal node;

[0009] when it is determined according to the node type that the current traversal node meets the function execution condition, calling a node calling parsing function, performing call chain parsing on the current traversal node, obtaining the call chain parsing result of the current traversal node, and storing the call chain parsing result of the current traversal node in an assignment dictionary;

[0010] When all the code nodes in the abstract code tree are traversed, the call chain list corresponding to the code file is obtained according to the assignment dictionary.

[0011] In a second aspect, the present application further provides a code file parsing device, comprising:

[0012] An abstract code tree generation module is configured to obtain a code file to be parsed, and generate an abstract code tree based on the code file.

[0013] A node type determination module is configured to traverse each code node in the abstract code tree, and determine the node type of each current traversed node.

[0014] A call chain parsing result obtaining module is configured to, when it is determined according to the node type that the current traversed node meets the function execution condition, call a node call parsing function, perform call chain parsing on the current traversed node, obtain the call chain parsing result of the current traversed node, and store the call chain parsing result of the current traversed node into an assignment dictionary.

[0015] A call chain list obtaining module is configured to, when all the code nodes in the abstract code tree are traversed, obtain the call chain list corresponding to the code file according to the assignment dictionary.

[0016] In a third aspect, the present application further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the following steps when executing the computer program:

[0017] Obtaining a code file to be parsed, and generating an abstract code tree based on the code file.

[0018] Traversing each code node in the abstract code tree, and determining the node type of each current traversed node.

[0019] When it is determined according to the node type that the current traversed node meets the function execution condition, calling a node call parsing function, performing call chain parsing on the current traversed node, obtaining the call chain parsing result of the current traversed node, and storing the call chain parsing result of the current traversed node into an assignment dictionary.

[0020] When all the code nodes in the abstract code tree are traversed, the call chain list corresponding to the code file is obtained according to the assignment dictionary.

[0021] In a fourth aspect, the present application further provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the following steps:

[0022] obtaining a code file to be parsed, and generating an abstract code tree based on the code file;

[0023] traversing each code node in the abstract code tree, and determining a node type of a current traversed node for each current traversed node;

[0024] when it is determined according to the node type that the current traversed node meets a parsing function execution condition, calling a node calling parsing function, performing call chain parsing on the current traversed node, obtaining a call chain parsing result of the current traversed node, and storing the call chain parsing result of the current traversed node into an assignment dictionary;

[0025] when all code nodes in the abstract code tree are traversed, obtaining a call chain list corresponding to the code file according to the assignment dictionary.

[0026] In a fifth aspect, the present application further provides a computer program product, comprising a computer program which, when executed by a processor, implements the following steps:

[0027] obtaining a code file to be parsed, and generating an abstract code tree based on the code file;

[0028] traversing each code node in the abstract code tree, and determining a node type of a current traversed node for each current traversed node;

[0029] when it is determined according to the node type that the current traversed node meets a parsing function execution condition, calling a node calling parsing function, performing call chain parsing on the current traversed node, obtaining a call chain parsing result of the current traversed node, and storing the call chain parsing result of the current traversed node into an assignment dictionary;

[0030] when all code nodes in the abstract code tree are traversed, obtaining a call chain list corresponding to the code file according to the assignment dictionary.

[0031] In the code file parsing method, the code file to be parsed is obtained, an abstract code tree is generated based on the code file, and each code node in the abstract code tree is traversed, so as to determine, for each current traversal node, the node type of the current traversal node. Further, when it is determined according to the node type that the current traversal node meets the function execution condition, a parsing function is called to perform call chain parsing on the current traversal node, and a call chain parsing result of the current traversal node is obtained, thereby effectively parsing the code file package and obtaining the dependency call relationship between different code file packages. The call chain parsing result of the current traversal node is stored in an assignment dictionary, and when all the code nodes in the abstract code tree are traversed, a call chain list corresponding to the code file is obtained according to the assignment dictionary, so that the call chain list can be used to accurately locate the unavailable code file package in the upgrade development process, and the code file package can be repaired in time to avoid application program crashes. BRIEF DESCRIPTION OF DRAWINGS

[0032] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related art, the drawings needed to be used in the description of the embodiments of the present application or the related art will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other related drawings can also be obtained without creative labor.

[0033] Figure 1 An application environment diagram of the code file parsing method in an embodiment;

[0034] Figure 2 A flowchart of the code file parsing method in an embodiment;

[0035] Figure 3 A call chain list diagram of the code file in an embodiment;

[0036] Figure 4 A flowchart of the code file parsing method in another embodiment;

[0037] Figure 5 A flowchart of obtaining the call chain parsing result of the current traversal node in an embodiment;

[0038] Figure 6 A flowchart of obtaining the call chain parsing result of the current traversal node in another embodiment;

[0039] Figure 7 A flowchart of the code file parsing method in another embodiment;

[0040] Figure 8A flowchart of a code file parsing method in another embodiment;

[0041] Figure 9 A structural block diagram of a code file parsing device in an embodiment;

[0042] Figure 10 An internal structure diagram of a computer device in an embodiment. DETAILED DESCRIPTION

[0043] In order to make the purposes, technical solutions and advantages of the present application clearer, the present application is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and not used to limit the present application.

[0044] The code file parsing method provided by the embodiments of the present application specifically relates to cloud storage technology in cloud technology. The cloud technology refers to a series of resources such as hardware, software and network being unified to realize data calculation, storage, processing and sharing in a wide area network or a local area network. Specifically, the cloud technology is a general term of network technology, information technology, integration technology, management platform technology and application technology based on cloud computing business model application, which can form a resource pool and be used on demand flexibly and conveniently. The background service of a technical network system needs a large amount of computing and storage resources, such as video websites, picture websites and more portal websites, and the cloud computing technology will become an important support in the actual application process of the technical network system.

[0045] The cloud storage is a new concept extended and developed on the basis of the cloud computing concept. The distributed cloud storage system (hereinafter referred to as the storage system) refers to a storage system in which a large number of storage devices (storage devices are also referred to as storage nodes) of various types are collected and cooperatively work together to provide data storage and business access functions through the functions of cluster application, grid technology and distributed storage file system. The storage method of the storage system is as follows: a logical volume is created, and a physical storage space is allocated to each logical volume when the logical volume is created. The physical storage space may be a disk of a storage device or a disk group of several storage devices. The client stores data on a certain logical volume, that is, stores data on the file system. The file system divides the data into many parts, each part being an object. The object contains not only data but also additional information such as data ID (ID entity). The file system writes each object into the physical storage space of the logical volume, and records the storage location information of each object. Thus, when the client requests to access data, the file system can enable the client to access the data according to the storage location information of each object. The process of allocating the physical storage space to the logical volume by the storage system is as follows: the physical storage space is divided into sections according to the capacity estimation of the objects stored in the logical volume (the estimation often has a large margin relative to the actual capacity of the objects to be stored) and the group of RAID (Redundant Array of Independent Disk). A logical volume can be understood as a section, so that the physical storage space is allocated to the logical volume.

[0046] With the development of the Internet, real-time data flow and connected devices, and the demand of search services, social networks, mobile commerce and open collaboration, cloud technology has rapidly developed. Unlike previous data storage and data computing, the generation of cloud technology will change the entire Internet model and enterprise management model.

[0047] The code file parsing method provided by the embodiment of the present application can be applied to, for example Figure 1The application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. Among them, the data storage system can store the data required by the server 104 to process, the data storage system can be set separately, can be integrated on the server 104, or can be placed on the cloud or other network servers. Among them, the terminal 102 can be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, Internet of Things devices, and portable wearable devices. The Internet of Things device can be a smart speaker, a smart TV, a smart air conditioner, a smart vehicle device, etc. The portable wearable device can be a smart watch, a smart bracelet, a head-mounted device, etc. The server 104 can be a standalone physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs, and big data and artificial intelligence platforms. Basic cloud computing services such as platform. The terminal 102 and the server 104 can be connected directly or indirectly through wired or wireless communication, which is not limited in the present application.

[0048] Among them, the terminal device 102 and the server 104 can be used alone to execute the code file parsing method provided in the embodiments of the present application, and the terminal device 102 and the server 104 can also cooperate to execute the code file parsing method provided in the embodiments of the present application. For example, taking the terminal device 102 and the server 104 cooperating to execute the code file parsing method provided in the embodiments of the present application as an example, the server 104 acquires the code file to be parsed, generates an abstract code tree based on the code file, and traverses each code node in the abstract code tree. For each current traversal node, determine the node type of the current traversal node. Further, when the server 104 determines that the current traversal node satisfies the parsing function execution condition according to the node type, the node calls the parsing function, and performs call chain parsing on the current traversal node to obtain the call chain parsing result of the current traversal node. Among them, the server 104 specifically stores the call chain parsing result of the current traversal node to the assignment dictionary, so that when all code nodes in the abstract code tree are traversed, the call chain list corresponding to the code file can be obtained according to the assignment dictionary, and the call chain list is fed back to the terminal device 102 for display.

[0049] In one exemplary embodiment, as Figure 2 shown, a code file parsing method is provided. Taking the server 104 in Figure 1 as an example, the method includes the following steps S202 to S208. Among them:

[0050] Step S202, acquiring a code file to be parsed, and generating an abstract code tree based on the code file.

[0051] The code file to be parsed can be a code file in a software package involved in the development or upgrade of an application or system, such as different code files in a software package developed using a computer programming language (such as Python).

[0052] Specifically, the server obtains the code file to be parsed by obtaining a software package involved in the development or upgrade of an application or system, such as a software package developed using a computer programming language, and parsing the software package to obtain different code files contained in the software package, and then parses the code file to be parsed and compiles it into an abstract code tree represented by an abstract syntax structure.

[0053] Further, the syntax parsing structure in the code file is obtained by parsing the code file to be parsed, and the syntax parsing structure in the code file is compiled by an abstract syntax tree (AST, i.e., abstract syntax code), that is, the code file is represented in a tree form by using the abstract syntax structure in the abstract syntax tree, and an abstract code tree represented by an abstract syntax structure is obtained.

[0054] The abstract syntax tree refers to a tree representation of the abstract syntax structure of the source code, that is, each node on the abstract syntax tree represents a part of the source code, such as an expression or a statement in the code. For example, a Python file in a software package developed using a computer programming language (such as Python) is obtained, the Python file is parsed, and the Python file is represented in a tree form by using the abstract syntax structure in the abstract syntax tree, and a Python abstract syntax tree represented by an abstract syntax structure is obtained, that is, an abstract code tree corresponding to the code file (such as the Python file) is obtained.

[0055] Step S204: Each code node in the abstract code tree is traversed, and for each current traversal node, the node type of the current traversal node is determined.

[0056] The abstract code tree obtained based on the code file to be parsed includes a plurality of code nodes, which can be understood as a part of the code file, such as a certain code node corresponding to a certain expression in the code file, another code node corresponding to a certain statement in the code file, which can be a judgment statement or an assignment statement.

[0057] Specifically, the server determines the node type of each code node in the obtained abstract code tree as a current traversal node respectively by traversing each code node in the abstract code tree, and determines the node type of each current traversal node. The node type of the current traversal node specifically includes an assignment statement node, a function call node, a type access statement node, and an imported module node, and the like.

[0058] For example, the assignment statement node in the code file (such as a Python file) corresponds to the assignment statement in the source code, and the basic form is that the left side of the assignment statement equal sign is the target of the assignment statement, and the object to be assigned is located on the right side. The left side target can be a variable name or an element. The function call node refers to a code node that needs to call other functions in the code file or call external functions, and the type access statement node includes a visitor node and a visited node, such as a type access statement node A.B, where A is a visitor node and B is a visited node.

[0059] The imported module node refers to the import module node in the code file (such as a Python file), which specifically includes an import node (understood as a direct import module node) and an ImportFrom node (understood as an indirect import module node). The import node is used to directly import the entire module and build a module object, for example, import ABC is to import “ABC” and store it in the import dictionary corresponding to the import node. The ImportFrom node is used to import a module and some attributes (or specific content) in the module, such as From ABC Import EFG, the imported data is ABC as the key and EFG as the value, and the key-value pair (i.e., the ABC-EFG pair) is stored in the ImportFrom dictionary corresponding to the ImportFrom node.

[0060] In an exemplary embodiment, before determining the node type of each current traversal node in the abstract code tree, a parent node is added to each code node in the abstract code tree to determine the position of the current traversal node. Each code node in the abstract code tree, except the root node, has and only has one parent node. In order to record the parent-child relationship between the code nodes in the abstract code tree, a parent field is added to each node to record the parent node of the node.

[0061] In step S206, when it is determined according to the node type that the current traversal node satisfies the function execution condition, the node calls the parsing function, performs call chain parsing on the current traversal node, obtains the call chain parsing result of the current traversal node, and stores the call chain parsing result of the current traversal node in the assignment dictionary.

[0062] Specifically, the server determines that the current traversed node satisfies the parsing function execution condition when determining, according to the node type of the current traversed node, that the current traversed node satisfies the parsing function execution condition, such as when the node type of the current traversed node is an assignment statement node and the node type of the right child node in the assignment statement node is a function call node.

[0063] For example, when determining whether the current traversed node satisfies the parsing function execution condition, it can also be determined that the current traversed node satisfies the parsing function execution condition when the node type of the current traversed node is not an assignment statement node but a function call node.

[0064] Optionally, when determining whether the current traversed node satisfies the parsing function execution condition, it can also be determined that the current traversed node satisfies the parsing function execution condition when the node type of the current traversed node is not an assignment statement node and a function call node, but a type access statement node, and further determining whether the assignment data of the current traversed node belongs to the context assignment type. Wherein, if the assignment data of the current traversed node does not belong to the context assignment type, it is determined that the current traversed node satisfies the parsing function execution condition.

[0065] Further, when the current traversed node satisfies the parsing function execution condition, the node calls the parsing function to perform call chain parsing on the current traversed node to obtain the call chain parsing result of the current traversed node, that is, to obtain all function interface call conditions used by the current traversed node. Wherein, after obtaining the call chain parsing result of each current traversed node, the call chain parsing result of each current traversed node is stored in the assignment dictionary.

[0066] Step S208, when all code nodes in the abstract code tree are traversed, the call chain list corresponding to the code file is obtained according to the assignment dictionary.

[0067] Specifically, if the server determines that all code nodes in the abstract code tree have been traversed, that is, the assignment dictionary obtained stores the call chain parsing result corresponding to each current traversed node, and further, the call chain list corresponding to the entire code file can be obtained based on the assignment dictionary, that is, all function interface call chain lists used by the entire code file are obtained.

[0068] In one exemplary embodiment, as Figure 3 shown, a call chain list diagram of a code file is provided, as Figure 3 known, root@ test indicates a test case for generating a call chain list, and the parsed code file (such as Figure 3In the call chain list in the shown python3 tox.py file, the call resolution results of multiple code nodes are included, such as the call resolution result "tox.*config" for indicating a call to a configuration file, the call resolution result "jinja2.Template" for indicating a call to a string template, the call resolution result "pkgutil.get_data" for indicating a data call, and the call resolution result "tox.config.parseconfig" for indicating a configuration file reading, and the like.

[0069] In the above code file parsing method, the code file to be parsed is obtained, an abstract code tree is generated based on the code file, and each code node in the abstract code tree is traversed, so as to determine the node type of each current traversal node. Further, when it is determined according to the node type that the current traversal node satisfies the function execution condition, the node call resolution function is called to perform call chain resolution on the current traversal node, and the call chain resolution result of the current traversal node is obtained, so as to effectively parse the code file package and obtain the dependency call relationship between different code file packages. Wherein, the call chain resolution result of the current traversal node is stored in the assignment dictionary, and when all the code nodes in the abstract code tree are traversed, the call chain list corresponding to the code file is obtained according to the assignment dictionary, so as to accurately locate the unavailable code file package in the upgrade development process based on the call chain list, and timely repair the code file package to avoid application program crash.

[0070] In an exemplary embodiment, as shown in Figure 4 A code file parsing method is provided, which is applied to the server 104 in Figure 1 for example, and includes the following steps S402 to S414. Wherein:

[0071] Step S402, obtaining the code file to be parsed, and generating an abstract code tree based on the code file.

[0072] Specifically, the server obtains the software package involved in the development and upgrade process of the application program or system, such as the software package developed by using computer programming language, and obtains the code file to be parsed contained in the software package by parsing the software package, and compiles the code file to be parsed into an abstract code tree represented by abstract syntax structure by parsing the code file to be parsed.

[0073] Step S404, traversing each code node in the abstract code tree, and determining the node type of each current traversal node.

[0074] Specifically, the server determines the node type of each code node in the obtained abstract code tree as a current traversal node respectively by traversing each code node in the obtained abstract code tree, and determines the node type of each current traversal node. The node type of the current traversal node specifically includes an assignment statement node, a function call node, a type access statement node, and an import module node, and the like.

[0075] The assignment statement node corresponds to an assignment statement in the source code, the function call node refers to a code node that needs to call other functions in the code file or call external functions, the type access statement node includes a visitor node and a visited node, such as a type access statement node A.B, where A is the visitor node and B is the visited node. The import module node refers to an import module node in the code file (such as a Python file), which specifically includes an import node (understood as a direct import module node) and an ImportFrom node (understood as an indirect import module node).

[0076] Step S406, when the node type of the current traversal node is an assignment statement node, and the node type of the right child node in the assignment statement node is a function call node, the right child node is taken as the current traversal node, and it is determined that the current traversal node satisfies the function execution condition.

[0077] Specifically, the node type of the current traversal node specifically includes an assignment statement node, a function call node, a type access statement node, and an import module node, and the like. The server first determines whether the node type of the current traversal node is an assignment statement node. If the node type of the current traversal node is an assignment statement node, the node type of the right child node in the assignment statement node is obtained. Then, it is determined whether the node type of the right child node in the assignment statement node is a function call node.

[0078] Further, if the server determines that the node type of the right child node in the assignment statement node is a function call node, the right child node is taken as the current traversal node, and it is determined that the current traversal node satisfies the function execution condition.

[0079] After step S404, step S408 is performed. When the node type of the current traversal node is not an assignment statement node, and the node type of the current traversal node is a function call node, it is determined that the current traversal node satisfies the function execution condition.

[0080] Specifically, the server first determines whether the node type of the current traversal node is an assignment statement node. If the node type of the current traversal node is not an assignment statement node, it is determined whether the node type of the current traversal node is a function call node.

[0081] Further, if the server determines that the node type of the current traversed node is a function call node and that the current traversed node satisfies the function execution condition, the server determines that the current traversed node satisfies the function execution condition, and the node calls the parsing function to perform call chain parsing on the current traversed node.

[0082] After step S404, step S410 is performed. If the node type of the current traversed node is a type access statement node and the assignment data of the current traversed node does not belong to the context assignment type, it is determined that the current traversed node satisfies the function execution condition.

[0083] Specifically, the server first determines whether the node type of the current traversed node is an assignment statement node. If the node type of the current traversed node is not an assignment statement node, the server determines whether the node type of the current traversed node is a function call node. If the node type of the current traversed node is not a function call node, the server further determines whether the node type of the current traversed node is a type access statement node.

[0084] Further, if the server determines that the node type of the current traversed node is a type access statement node, the server obtains the assignment data of the current traversed node and determines whether the assignment data of the current traversed node belongs to the context assignment type. If the node type of the current traversed node is a type access statement node and the assignment data of the current traversed node does not belong to the context assignment type, it is determined that the current traversed node satisfies the function execution condition, and the node calls the parsing function to perform call chain parsing on the current traversed node.

[0085] The context assignment type means that the assignment data of the current traversed node is a context to be assigned, and the context to be assigned corresponds to ctx = load() in the abstract code tree structure, that is, the current traversed node is a node for accessing a variable or a function, where "ctx" corresponds to context, "load()" means opening a file.

[0086] After step S406, or step S408 or step S410, step S412 is performed. When it is determined according to the node type that the current traversed node satisfies the function execution condition, the node calls the parsing function to perform call chain parsing on the current traversed node, the call chain parsing result of the current traversed node is obtained, and the call chain parsing result of the current traversed node is stored in the assignment dictionary.

[0087] Specifically, the server determines that the current traversed node meets the function execution condition when determining, according to the node type of the current traversed node, that the current traversed node meets the function execution condition, such as when the node type of the current traversed node is an assignment statement node and the node type of the right child node in the assignment statement node is a function call node, or when the node type of the current traversed node is not an assignment statement node but a function call node, or when the node type of the current traversed node is not an assignment statement node and a function call node but a type access statement node, and the assignment data of the current traversed node does not belong to the context assignment type.

[0088] Further, when the current traversed node meets the function execution condition, the server calls the parsing function to perform call chain parsing on the current traversed node to obtain the call chain parsing result of the current traversed node, that is, to obtain all function interface call conditions used by the current traversed node. After obtaining the call chain parsing result of each current traversed node, the call chain parsing result of each current traversed node is stored in the assignment dictionary.

[0089] Step S414: When all code nodes in the abstract code tree are traversed, the call chain list corresponding to the code file is obtained according to the assignment dictionary.

[0090] Specifically, if the server determines that all code nodes in the abstract code tree have been traversed, that is, the assignment dictionary stores the call chain parsing result corresponding to each current traversed node, and the call chain list corresponding to the entire code file can be obtained based on the assignment dictionary, that is, the entire code file uses all function interface call chain lists.

[0091] In the code file parsing method, the code file to be parsed is obtained, an abstract code tree is generated based on the code file, and each code node in the abstract code tree is traversed. For each current traversal node, the node type of the current traversal node is determined. Wherein, when the node type of the current traversal node is an assignment statement node, and the node type of the right child node in the assignment statement node is a function call node, the right child node is taken as the current traversal node, and it is determined that the current traversal node satisfies the function execution condition of the parsing function, or when the node type of the current traversal node is not an assignment statement node, and the node type of the current traversal node is a function call node, it is determined that the current traversal node satisfies the function execution condition of the parsing function, or in the case that the node type of the current traversal node is not an assignment statement node and a function call node, if the node type of the current traversal node is a type access statement node, and the assignment data of the current traversal node does not belong to the context assignment type, it is determined that the current traversal node satisfies the function execution condition of the parsing function. When it is determined that the current traversal node satisfies the function execution condition of the parsing function according to the node type, the parsing function is called to perform call chain parsing on the current traversal node to obtain the call chain parsing result of the current traversal node, thereby effectively parsing the code file package and obtaining the dependency call relationship between different code file packages. Further, the call chain parsing result of the current traversal node is stored in the assignment dictionary, so that the call chain list corresponding to the code file can be obtained according to the assignment dictionary when all the code nodes in the abstract code tree are traversed, thereby accurately positioning the unavailable code file package based on the call chain list during the upgrade development process, and timely repairing the code file package to avoid application program crash.

[0092] In one exemplary embodiment, as shown in Figure 5 The step of obtaining the call chain parsing result of the current traversal node, i.e. when it is determined that the current traversal node satisfies the function execution condition of the parsing function according to the node type, the parsing function is called to perform call chain parsing on the current traversal node to obtain the call chain parsing result of the current traversal node, specifically includes the following steps S502 to S508. Wherein:

[0093] Step S502, when it is determined that the current traversal node satisfies the function execution condition of the parsing function according to the node type, the parsing function is called to obtain the node type of the current traversal node.

[0094] Specifically, the server determines that the current traversed node satisfies the function execution condition when determining, according to the node type of the current traversed node, that the current traversed node satisfies the function execution condition, such as when the node type of the current traversed node is an assignment statement node and the node type of the right child node in the assignment statement node is a function call node, or when the node type of the current traversed node is not an assignment statement node but a function call node, or when the node type of the current traversed node is not an assignment statement node and a function call node but a type access statement node, and the assignment data of the current traversed node does not belong to the context assignment type. When the current traversed node satisfies the function execution condition, the server further acquires the node type of the current traversed node by calling the node to call the parsing function.

[0095] When the server calls the node to call the parsing function to determine the node type of the current traversed node, the server specifically determines whether the current traversed node belongs to a type access statement node or an introduced module node.

[0096] In step S504, if the current traversed node does not belong to a type access statement node and the current traversed node belongs to an introduced module node, the server queries the introduced module dictionary according to the current traversed node.

[0097] Specifically, the server determines whether the current traversed node belongs to a type access statement node by calling the node to call the parsing function. If the current traversed node does not belong to a type access statement node, the server determines whether the current traversed node belongs to an introduced module node.

[0098] Further, if the current traversed node does not belong to a type access statement node and the current traversed node belongs to an introduced module node, the server queries the introduced module dictionary according to the current traversed node.

[0099] The introduced module node specifically includes a direct introduced module node and an indirect introduced module node, and the introduced module dictionary specifically includes a first introduced module dictionary corresponding to the direct introduced module node and a second introduced module dictionary corresponding to the indirect introduced module node. Specifically, the server queries the first introduced module dictionary according to the current traversed node first. If the current traversed node does not exist in the first introduced module dictionary, the server queries the second introduced module dictionary according to the current traversed node.

[0100] In step S506, when the current traversed node exists in the introduced module dictionary, the server acquires the storage identifier of the current traversed node in the introduced module dictionary.

[0101] Specifically, when the first import module dictionary is queried according to the current traversal node, it is determined whether the current traversal node exists in the first import module dictionary.

[0102] If the current traversal node exists in the first import module dictionary, a first storage identifier of the current traversal node in the first import module dictionary is obtained. The first storage identifier of the current traversal node in the first import module dictionary can be in the form of "imports[id]", that is, the storage location of the current traversal node in the first import module dictionary (that is, the import dictionary).

[0103] Conversely, if the current traversal node does not exist in the first import module dictionary, the second import module dictionary is queried according to the current traversal node. If the current traversal node exists in the second import module dictionary, a second storage identifier of the current traversal node in the second import module dictionary is obtained. The second storage identifier of the current traversal node in the second import module dictionary can be in the form of "from_imports[id].id", that is, the storage location of the current traversal node in the second import module dictionary (that is, the ImportFrom dictionary).

[0104] In step S508, the call chain analysis result of the current traversal node is obtained according to the storage identifier.

[0105] Specifically, the call chain analysis result of the current traversal node is obtained according to the first storage identifier of the current traversal node in the first import module dictionary or according to the second storage identifier of the current traversal node in the second import module dictionary.

[0106] The purpose of determining whether the current traversal node is located in the first import module dictionary or the second import module dictionary is to determine whether an external module introduced by the import node or the ImportFrom node is involved, that is, whether there is a function call chain introduced from the outside in the code file (such as a python file), so as to analyze whether the specified function and variable are used externally, so that when upgrading or changing, other external code file packages affected by the change can be accurately found, and the affected interface or unavailable code file package can be located, so that code file package repair can be performed in time to avoid application crashes.

[0107] Further, the first storage identifier or the second storage identifier can be used to determine whether the current traversal node belongs to the direct import module node or the indirect import module node, and then the specific external function or external interface called by the current traversal node can be obtained, i.e., the call chain analysis result of the current traversal node calling the external function (or interface) or not calling the external function (or interface) can be obtained.

[0108] In the embodiment, when it is determined according to the node type that the current traversal node satisfies the function execution condition, the node calls the analysis function to obtain the node type of the current traversal node, and when it is determined that the current traversal node does not belong to the type access statement node and the current traversal node belongs to the import module node, the current traversal node is queried in the import module dictionary, so that the storage identifier of the current traversal node in the import module dictionary can be obtained when the current traversal node exists in the import module dictionary. Thus, the call chain analysis result of the current traversal node can be obtained according to the storage identifier, and based on the call chain analysis result, it can be determined whether there is a function call chain introduced from outside in the code file, and then it can be analyzed whether the specified function and variable are used by the outside, so that when upgrading or changing, other external code file packages affected by the change can be accurately found, and the affected interface or unavailable code file package can be located, so that timely code file package repair can be performed to avoid application crashes.

[0109] In an exemplary embodiment, as shown in Figure 6 The step of obtaining the call chain analysis result of the current traversal node, i.e., the step of calling the analysis function by the node when it is determined according to the node type that the current traversal node satisfies the function execution condition, performing call chain analysis on the current traversal node, and obtaining the call chain analysis result of the current traversal node, specifically includes the following steps S602 to S612. Wherein:

[0110] Step S602, when it is determined according to the node type that the current traversal node satisfies the function execution condition, the node calls the analysis function to obtain the node type of the current traversal node.

[0111] Specifically, the server determines that the current traversed node satisfies the function execution condition when determining, according to the node type of the current traversed node, that the current traversed node satisfies the function execution condition, such as when the node type of the current traversed node is an assignment statement node and the node type of the right child node in the assignment statement node is a function call node, or when the node type of the current traversed node is not an assignment statement node but a function call node, or when the node type of the current traversed node is not an assignment statement node and a function call node but a type access statement node, and the assignment data of the current traversed node does not belong to the context assignment type. When the current traversed node satisfies the function execution condition, the server calls the node to call the parsing function to further obtain the node type of the current traversed node.

[0112] When the server calls the node to call the parsing function to determine the node type of the current traversed node, the server specifically determines whether the current traversed node belongs to a type access statement node or a variable node.

[0113] In step S604, when the current traversed node belongs to a type access statement node, the server determines the return value corresponding to the visitor node in the current traversed node.

[0114] Specifically, the server calls the node to call the parsing function to determine whether the current traversed node belongs to a type access statement node. If the current traversed node belongs to a type access statement node, the server obtains the return value corresponding to the visitor node in the current traversed node. The return value corresponding to the visitor node in the current traversed node includes two cases: empty or not empty.

[0115] In step S606, if the return value is not empty and the accessed node in the current traversed node belongs to a variable node, the server obtains the recursive query result corresponding to the accessed node.

[0116] Specifically, if the server determines that the return value corresponding to the visitor node in the current traversed node is not empty, the server obtains the node type of the accessed node in the current traversed node and determines whether the accessed node in the current traversed node belongs to a variable node. If the accessed node in the current traversed node belongs to a variable node, the server obtains the recursive query result corresponding to the accessed node.

[0117] If the accessed node in the current iteration node belongs to a variable node, the recursive query result of "call.*attr" is returned, and if the accessed node in the current iteration node does not belong to a variable node, the recursive query result of "call.attr" is returned. The recursive query result is distinguished between a variable and a function by means of "*". That is, the recursive query result carrying "*" indicates that a variable is returned currently, and the recursive query result not carrying "*" indicates that a function is returned currently.

[0118] For example, if there are type access statement nodes a = b.d and c = a.e, and e is a variable, "call.*attr" refers to the result b.d found recursively starting from a, and *attr refers to the variable e, so the finally returned "call.*attr" is "b.d.*e".

[0119] For another example, if there are type access statement nodes a = b.d and c = a.e(), and e is a function, "call.attr" refers to the result b.d found recursively starting from a, and attr refers to the function e, so the finally returned "call.attr" is "b.d.e" without "*".

[0120] In step S608, the call chain parsing result of the current iteration node is obtained according to the recursive query result.

[0121] Specifically, according to the recursive query result corresponding to the accessed node, such as the recursive query result of "call.*attr" when the accessed node in the current iteration node belongs to a variable node, and the recursive query result of "call.attr" when the accessed node in the current iteration node does not belong to a variable node, it can be determined whether the current iteration node calls a function or other variable, and then the call chain parsing result of the current iteration node about function call or variable call is obtained.

[0122] After step S604, step S610 is performed. If the return value is empty, and it is determined that the accessed node is located in the assignment dictionary, and the accessed node in the current iteration node belongs to a variable node, the variable value corresponding to the accessed node is obtained based on the assignment dictionary.

[0123] Specifically, if the server determines that the value corresponding to the accessed node in the current iteration node is empty, it is judged whether the accessed node in the current iteration node is located in the assignment dictionary, and whether the accessed node in the current iteration node belongs to a variable node.

[0124] Further, if the server determines that the value corresponding to the visitor node in the current traversal node is empty, and determines that the visitor node is located in the assignment dictionary, and the visited node in the current traversal node belongs to the variable node, the assignment dictionary is queried to obtain the variable value corresponding to the visitor node in the current traversal node.

[0125] Wherein, if the server determines that the visitor node is located in the assignment dictionary, and the visited node in the current traversal node belongs to the variable node, the assignment dictionary is queried to obtain the variable value corresponding to the visitor node in the current traversal node, which is specifically "assignments[node.value.id].*attr". Conversely, if the server determines that the visitor node is located in the assignment dictionary, and the visited node in the current traversal node does not belong to the variable node, the assignment dictionary is queried to obtain the variable value corresponding to the visitor node in the current traversal node, which is specifically "assignments[node.value.id].attr". Wherein, the "*" is used to distinguish between variables and functions, that is, the recursive query result carrying "*" indicates that the current return is a variable, and the recursive query result not carrying "*" indicates that the current return is a function.

[0126] Further, assignments corresponds to the assignment dictionary, node corresponds to the current traversal node, value corresponds to the visitor node, and attr corresponds to the visited node. Therefore, "assignments[node.value.id].*attr" or "assignments[node.value.id].attr" can be specifically understood as the variable value corresponding to the visitor node value found in the assignment dictionary.

[0127] For example, if A is the visitor node value, B is the visited node attr (at this time the visited node attr does not belong to the variable node), and the assignment dictionary records A = B.C, then the variable value queried based on the assignment dictionary is B.C. For another example, A is the visitor node value, B is the visited node *attr (at this time the visited node *attr belongs to the variable node), and the assignment dictionary records A = B.C, then the variable value queried based on the assignment dictionary is *B.C.

[0128] In step S612, the call chain parsing result of the current traversal node is obtained according to the variable value corresponding to the visitor node.

[0129] Specifically, according to the variable value corresponding to the visitor node, such as the variable value "assignments[node.value.id].*attr" obtained when it is determined that the visitor node is located in the assignment dictionary and the visited node in the current iteration node belongs to the variable node, or the variable value "assignments[node.value.id].attr" obtained when it is determined that the visitor node is located in the assignment dictionary and the visited node in the current iteration node does not belong to the variable node, it can be determined whether the current iteration node specifically calls a function or other variables, and then the call chain parsing result of the current iteration node about function call or variable call is obtained.

[0130] In the embodiment, when it is determined according to the node type that the current iteration node satisfies the parsing function execution condition, the node calls the parsing function to obtain the node type of the current iteration node, when the current iteration node belongs to the type access statement node, the return value corresponding to the visitor node in the current iteration node is determined, and when the return value is not empty and the visited node in the current iteration node belongs to the variable node, the recursive query result corresponding to the visited node is obtained to obtain the call chain parsing result of the current iteration node according to the recursive query result. On the contrary, when the return value is empty, it is determined that the visitor node is located in the assignment dictionary and the visited node in the current iteration node belongs to the variable node, the variable value corresponding to the visitor node is obtained based on the assignment dictionary to obtain the call chain parsing result of the current iteration node according to the variable value corresponding to the visitor node, so that different call chain parsing methods can be flexibly selected under different conditions that the visited node in the current iteration node belongs to the variable node and does not belong to the variable node, to accurately obtain the call chain parsing result of the current iteration node about function call or variable call under different conditions, to effectively parse the code file package and obtain the dependency call relationship between different code file packages, to further improve the development efficiency of the application program or system and reduce the tedious operation in the development process.

[0131] In one exemplary embodiment, as shown in Figure 7 , a code file parsing method is provided, which is applied to the server 104 in Figure 1 for example, and includes the following steps:

[0132] In step S701, a code file to be parsed is obtained, and an abstract code tree is generated based on the code file.

[0133] In step S702, each code node in the abstract code tree is iterated, and for each current iteration node, the node type of the current iteration node is determined.

[0134] Step S703, the current traversed node with the node type of the direct introduction module node is stored into the first introduction module dictionary corresponding to the direct introduction module node.

[0135] Step S704, the current traversed node with the node type of the indirect introduction module node is stored into the second introduction module dictionary corresponding to the indirect introduction module node.

[0136] Step S705, it is judged whether the node type of the current traversed node is the assignment statement node.

[0137] Step S706, when the node type of the current traversed node is the assignment statement node, it is judged whether the node type of the right child node in the assignment statement node is the function call node.

[0138] Step S707, when the node type of the right child node in the assignment statement node is the function call node, the right child node is taken as the current traversed node, and it is determined that the current traversed node satisfies the function execution condition.

[0139] After step S705, step S708 is executed, and when the node type of the current traversed node is not the assignment statement node, it is judged whether the node type of the current traversed node is the function call node.

[0140] Step S709, when the node type of the current traversed node is the function call node, it is determined that the current traversed node satisfies the function execution condition.

[0141] After step S708, step S710 is executed, and when the node type of the current traversed node is not the assignment statement node and the function call node, it is judged whether the node type of the current traversed node is the type access statement node.

[0142] Step S711, when the node type of the current traversed node is the type access statement node, it is judged whether the assignment data of the current traversed node belongs to the context assignment type.

[0143] Step S712, if the assignment data of the current traversed node does not belong to the context assignment type, it is determined that the current traversed node satisfies the function execution condition.

[0144] After step S707, or step S709, or step S712, step S713 is executed, and when it is determined according to the node type that the current traversed node satisfies the function execution condition, the node calls the parsing function to obtain the node type of the current traversed node.

[0145] Step S714, if the current traversed node does not belong to the type access statement node, and the current traversed node belongs to the introduction module node, the first introduction module dictionary is inquired according to the current traversed node.

[0146] Step S715, judge whether the current traversal node exists in the first import module dictionary.

[0147] Step S716, when the current traversal node exists in the first import module dictionary, obtain the first storage identifier of the current traversal node in the first import module dictionary, and obtain the call chain analysis result of the current traversal node according to the first storage identifier.

[0148] Step S717 is executed after step S715 is executed, and when the current traversal node does not exist in the first import module dictionary, the second import module dictionary is queried according to the current traversal node.

[0149] Step S718, when the current traversal node exists in the second import module dictionary, obtain the second storage identifier of the current traversal node in the second import module dictionary, and obtain the call chain analysis result of the current traversal node according to the second storage identifier.

[0150] Step S719 is executed after step S716 or step S718 is executed, and the call chain analysis result of the current traversal node is stored to the assignment dictionary.

[0151] Step S720, when all code nodes in the abstract code tree are traversed, obtain the call chain list corresponding to the code file according to the assignment dictionary.

[0152] In the code file parsing method, the code file to be parsed is obtained, an abstract code tree is generated based on the code file, and each code node in the abstract code tree is traversed. For each current traversal node, the node type of the current traversal node is determined, and the current traversal node with the node type of the direct import module node is stored in the first import module dictionary corresponding to the direct import module node, and the current traversal node with the node type of the indirect import module node is stored in the second import module dictionary corresponding to the indirect import module node. Wherein, when the node type of the current traversal node is the assignment statement node, and the node type of the right child node in the assignment statement node is the function call node, the right child node is taken as the current traversal node, and it is determined that the current traversal node satisfies the function execution condition of parsing, or when the node type of the current traversal node is not the assignment statement node, and the node type of the current traversal node is the function call node, it is determined that the current traversal node satisfies the function execution condition of parsing, or in the case that the node type of the current traversal node is not the assignment statement node and the function call node, if the node type of the current traversal node is the type access statement node, and the assignment data of the current traversal node does not belong to the context assignment type, it is determined that the current traversal node satisfies the function execution condition of parsing, so that when the node type of the current traversal node is determined to satisfy the function execution condition of parsing, the node calls the parsing function to obtain the node type of the current traversal node. Wherein, if the current traversal node does not belong to the type access statement node, and the current traversal node belongs to the import module node, the first import module dictionary is queried according to the current traversal node, when the current traversal node exists in the first import module dictionary, the first storage identifier of the current traversal node in the first import module dictionary is obtained, and the call chain analysis result of the current traversal node is obtained according to the first storage identifier. When the current traversal node does not exist in the first import module dictionary, the second import module dictionary is queried according to the current traversal node, and when the current traversal node exists in the first import module dictionary, the second storage identifier of the current traversal node in the second import module dictionary is obtained, so as to obtain the call chain analysis result of the current traversal node according to the second storage identifier, thereby effectively parsing the code file package, and obtaining the dependent call relationship between different code file packages. Further, the call chain analysis result of the current traversal node is stored in the assignment dictionary, so that when all code nodes in the abstract code tree are traversed, the call chain list corresponding to the code file is obtained according to the assignment dictionary, so that in the upgrading development process, the call chain list can be used to accurately locate the unusable code file package, and the code file package can be repaired in time to avoid application crash.

[0153] In one exemplary embodiment, as shown in Figure 8 A code file parsing method is provided, which is applied to the server 104 in Figure 1 for example, including the following steps:

[0154] Step S801, when it is determined according to the node type that the current traversed node satisfies the parsing function execution condition, a node call parsing function is called to obtain the node type of the current traversed node.

[0155] Step S802, it is determined whether the node type of the current traversed node is the type access statement node.

[0156] Step S803, if the current traversed node does not belong to the type access statement node, it is determined whether the current traversed node belongs to the introduced module node.

[0157] Step S804, if the current traversed node belongs to the introduced module node, the first introduced module dictionary is queried according to the current traversed node.

[0158] Step S805, it is determined whether the current traversed node exists in the first introduced module dictionary.

[0159] Step S806, when the current traversed node exists in the first introduced module dictionary, a first storage identifier of the current traversed node in the first introduced module dictionary is obtained, and the call chain parsing result of the current traversed node is obtained according to the first storage identifier.

[0160] Step S807 is executed after step S805 is executed, and when the current traversed node does not exist in the first introduced module dictionary, the second introduced module dictionary is queried according to the current traversed node.

[0161] Step S808, when the current traversed node exists in the second introduced module dictionary, a second storage identifier of the current traversed node in the second introduced module dictionary is obtained, and the call chain parsing result of the current traversed node is obtained according to the second storage identifier.

[0162] Step S809 is executed after step S802 is executed, and when the current traversed node belongs to the type access statement node, the return value corresponding to the visitor node in the current traversed node is determined.

[0163] Step S810, it is determined whether the return value is empty.

[0164] Step S811, if the return value is not empty, it is determined whether the accessed node in the current traversed node belongs to the variable node.

[0165] Step S812, if the accessed node in the current traversed node belongs to the variable node, the recursive query result corresponding to the accessed node is obtained.

[0166] Step S813, the call chain parsing result of the current traversed node is obtained according to the recursive query result.

[0167] After step S810, step S814 is executed. If the return value is empty, it is determined whether the visitor node is located in the assignment dictionary and whether the visited node in the current traversal node belongs to a variable node.

[0168] In step S815, if the visitor node is located in the assignment dictionary and the visited node in the current traversal node belongs to a variable node, the variable value corresponding to the visitor node is obtained based on the assignment dictionary.

[0169] In step S816, the call chain parsing result of the current traversal node is obtained according to the variable value corresponding to the visitor node.

[0170] After step S806, or step S809, or step S813, or step S816 is executed, step S817 is executed to determine whether the recursion is ended.

[0171] If the recursion is not ended, the process jumps to step S809.

[0172] In step S818, if the recursion is ended, the call chain list corresponding to the code file is obtained based on the assignment dictionary.

[0173] In the code file parsing method, when it is determined according to the node type that the current traversed node meets the execution condition of the parsing function, the node calling parsing function is called to obtain the node type of the current traversed node, and when the current traversed node does not belong to the type access statement node and belongs to the introduced module node, the first introduced module dictionary is queried according to the current traversed node. When the current traversed node exists in the first introduced module dictionary, the first storage identifier of the current traversed node in the first introduced module dictionary is obtained, and the calling chain parsing result of the current traversed node is obtained according to the first storage identifier. When the current traversed node does not exist in the first introduced module dictionary, the second introduced module dictionary is queried according to the current traversed node, and when the current traversed node exists in the second introduced module dictionary, the second storage identifier of the current traversed node in the second introduced module dictionary is obtained, so that the calling chain parsing result of the current traversed node is obtained according to the second storage identifier. Further, when the current traversed node belongs to the type access statement node, the return value corresponding to the visitor node in the current traversed node is determined, if the return value is not empty and the visited node in the current traversed node belongs to the variable node, the recursive query result corresponding to the visited node is obtained, and the calling chain parsing result of the current traversed node is obtained according to the recursive query result. On the contrary, if the return value is empty, the visitor node is located in the assignment dictionary, and the visited node in the current traversed node belongs to the variable node, the variable value corresponding to the visitor node is obtained based on the assignment dictionary, the calling chain parsing result of the current traversed node is obtained according to the variable value corresponding to the visitor node, and when it is determined that the recursion is ended, the calling chain list corresponding to the code file is obtained according to the assignment dictionary, thereby effectively parsing the code file package and obtaining the dependent calling relationship between different code file packages, so as to accurately locate the unusable code file package based on the calling chain list in the upgrading development process, and timely repair the code file package to avoid application program crash.

[0174] It should be understood that, although each step in the flowchart involved in the above embodiments is displayed in sequence according to the arrow, these steps are not necessarily executed in the order indicated by the arrow. Unless otherwise specified herein, the execution of these steps is not strictly limited in sequence, and these steps can be executed in other orders. Moreover, at least part of the steps in the flowchart involved in the above embodiments can include multiple steps or stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily sequential, but can be alternately executed with at least part of other steps or steps or stages in other steps.

[0175] Based on the same inventive concept, the embodiments of the present application also provide a code file parsing device for implementing the code file parsing method described above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme described in the above method, so the specific limitations in one or more code file parsing device embodiments provided below can be referred to the limitations of the code file parsing method in the above, which will not be described here again.

[0176] In one exemplary embodiment, as shown in Figure 9 A code file parsing device is provided, comprising: an abstract code tree generation module 902, a node type determination module 904, a call chain parsing result obtaining module 906, and a call chain list obtaining module 908, wherein:

[0177] The abstract code tree generation module 902 is configured to obtain a code file to be parsed, and generate an abstract code tree based on the code file;

[0178] The node type determination module 904 is configured to traverse each code node in the abstract code tree, and determine the node type of a current traversed node for each current traversed node;

[0179] The call chain parsing result obtaining module 906 is configured to, when it is determined according to the node type that the current traversed node meets the function execution condition, call a node call parsing function, perform call chain parsing on the current traversed node, obtain the call chain parsing result of the current traversed node, and store the call chain parsing result of the current traversed node in an assignment dictionary;

[0180] The call chain list obtaining module 908 is configured to, when all code nodes in the abstract code tree are traversed, obtain a call chain list corresponding to the code file according to the assignment dictionary.

[0181] In the code file parsing device described above, the code file to be parsed is obtained, the abstract code tree is generated based on the code file, and each code node in the abstract code tree is traversed to determine the node type of the current traversed node for each current traversed node. Further, when it is determined according to the node type that the current traversed node meets the function execution condition, the node call parsing function is called, the call chain parsing is performed on the current traversed node, the call chain parsing result of the current traversed node is obtained, and the purpose of effectively parsing the code file package and obtaining the dependent call relationship between different code file packages is achieved. By storing the call chain parsing result of the current traversed node in the assignment dictionary, and obtaining the call chain list corresponding to the code file according to the assignment dictionary when all code nodes in the abstract code tree are traversed, the unusable code file package can be accurately located based on the call chain list during the upgrade development process, and the code file package repair can be performed in time to avoid the application program crash.

[0182] In an example embodiment, the code file parsing apparatus is further configured to determine, when the node type of the current traversed node is not the assignment statement node and the node type of the current traversed node is the function call node, that the current traversed node satisfies the parsing function execution condition.

[0183] In an example embodiment, the parsing function execution condition determining module is further configured to determine, when the node type of the current traversed node is not the assignment statement node and the node type of the current traversed node is the function call node, that the current traversed node satisfies the parsing function execution condition.

[0184] In an example embodiment, the parsing function execution condition determining module is further configured to determine, when the node type of the current traversed node is not the assignment statement node and the node type of the current traversed node is the function call node, that the current traversed node satisfies the parsing function execution condition.

[0185] In an example embodiment, the call chain parsing result obtaining module is further configured to, when it is determined according to the node type that the current traversed node satisfies the parsing function execution condition, call the parsing function to obtain the node type of the current traversed node; if the current traversed node does not belong to the type access statement node and the current traversed node belongs to the import module node, query the import module dictionary according to the current traversed node; when the current traversed node exists in the import module dictionary, obtain the storage identifier of the current traversed node in the import module dictionary; and obtain the call chain parsing result of the current traversed node according to the storage identifier.

[0186] In an example embodiment, the call chain parsing result obtaining module is further configured to, when the current traversed node belongs to the type access statement node, determine the return value corresponding to the visitor node in the current traversed node; if the return value is not empty and the visited node in the current traversed node belongs to the variable node, obtain the recursive query result corresponding to the visited node; and obtain the call chain parsing result of the current traversed node according to the recursive query result.

[0187] In an example embodiment, the call chain parsing result obtaining module is further configured to, if the return value is empty and it is determined that the visitor node is located in the assignment dictionary and the visited node in the current traversed node belongs to the variable node, obtain the variable value corresponding to the visitor node based on the assignment dictionary; and obtain the call chain parsing result of the current traversed node according to the variable value corresponding to the visitor node.

[0188] The modules in the code file parsing apparatus can be implemented by software, hardware, or a combination thereof. The modules can be embedded in or independent of a processor in a computer device in hardware form, or stored in a memory in the computer device in software form, so as to be invoked and executed by the processor to perform operations corresponding to the modules.

[0189] In an exemplary embodiment, a computer device is provided, which can be a server or a terminal device. Taking the server as an example, an internal structure diagram of the server can be as shown in FIG. 1. Figure 10 The computer device includes a processor, a memory, an input / output interface, and a communication interface. The processor, the memory, and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for running the operating system and the computer program in the non-volatile storage medium. The database of the computer device is configured to store data such as a code file to be parsed, an abstract code tree, a node type of a current traversal node, a node call parsing function, a call chain parsing result, an assignment dictionary, and a call chain list. The input / output interface of the computer device is configured to exchange information between the processor and external devices. The communication interface of the computer device is configured to communicate with a terminal device through a network connection. The computer program is executed by the processor to implement a code file parsing method.

[0190] Those skilled in the art can understand that Figure 10 The structure shown in FIG. 1 is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. Specifically, the computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0191] In an embodiment, a computer device is also provided, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.

[0192] In an embodiment, a computer readable storage medium is provided, which stores a computer program. The computer program is executed by a processor to implement the steps in the above method embodiments.

[0193] In an embodiment, a computer program product is provided, including a computer program which, when executed by a processor, implements the steps of any of the above method embodiments.

[0194] It should be noted that the user information (including but not limited to user equipment information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or authorized by all parties, and the collection, use and processing of related data need to comply with relevant regulations.

[0195] It can be understood by those skilled in the art that all or part of the processes in the above-mentioned embodiments can be completed by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer readable storage medium. When the computer program is executed, it can include the processes of the above-mentioned embodiments. Any reference to memory, database or other medium used in the embodiments provided by the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical storage, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration but not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The database involved in the embodiments provided by the present application can include at least one of a relational database and a non-relational database. The non-relational database can include a distributed database based on a block chain, etc., without being limited thereto. The processor involved in the embodiments provided by the present application can be a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., without being limited thereto.

[0196] Any combination of the technical features in the above embodiments can be made. For the sake of brevity, the foregoing description is not intended to be exhaustive or to limit the application to the precise form disclosed. Modifications or variations are possible in light of the above teachings. The embodiments were chosen and described in order to provide the best illustration of the principles of the application and its practical application, and to thereby enable one of ordinary skill in the art to utilize the application in various embodiments and with various modifications as are suited to the particular use contemplated. All such modifications and variations are within the scope of the application as determined by the appended claims when interpreted in accordance with the breadth to which they are fairly, legally, and equitably susceptible.

[0197] The above embodiments only express several implementation manners of the application, and the description is relatively specific and detailed, but it should not be understood as a limitation on the patent scope of the application. It should be pointed out that, for ordinary skilled persons in the art, some modifications and improvements can be made without departing from the concept of the application, and these all belong to the protection scope of the application. Therefore, the protection scope of the application should be subject to the appended claims.

Claims

1. A code file parsing method characterized by, The method comprises: acquiring a code file to be parsed, and generating an abstract code tree based on the code file; traversing each code node in the abstract code tree, determining the node type of each current traversing node; when it is determined according to the node type that the current traversing node meets a function execution condition for parsing, calling a node call parsing function, performing call chain parsing on the current traversing node, obtaining a call chain parsing result of the current traversing node, and storing the call chain parsing result of the current traversing node in an assignment dictionary; when all code nodes in the abstract code tree are traversed, obtaining a call chain list corresponding to the code file according to the assignment dictionary.

2. The method of claim 1, wherein, The method further comprises: when the node type of the current traversing node is an assignment statement node, and the node type of a right child node in the assignment statement node is a function call node, taking the right child node as a current traversing node, and determining that the current traversing node meets the function execution condition for parsing.

3. The method of claim 1, wherein, The method further comprises: when the node type of the current traversing node is not an assignment statement node, and the node type of the current traversing node is a function call node, determining that the current traversing node meets the function execution condition for parsing.

4. The method of claim 1, wherein, The method further comprises: when the node type of the current traversing node is not an assignment statement node and a function call node, if the node type of the current traversing node is a type access statement node, and the assignment data of the current traversing node does not belong to a context assignment type, it is determined that the current traversing node meets the function execution condition for parsing.

5. The method according to any one of claims 1 to 4, characterized in that, The method further comprises: when it is determined according to the node type that the current traversing node meets the function execution condition for parsing, calling a node call parsing function to obtain the node type of the current traversing node; if the current traversing node does not belong to a type access statement node, and the current traversing node belongs to an imported module node, querying an imported module dictionary according to the current traversing node; when the current traversing node exists in the imported module dictionary, obtaining a storage identifier of the current traversing node in the imported module dictionary; obtaining the call chain parsing result of the current traversing node according to the storage identifier.

6. The method of claim 5, wherein, The method further comprises: when the current traversing node belongs to a type access statement node, determining a return value of an accessor node in the current traversing node; if the return value is not empty, and an accessed node in the current traversing node belongs to a variable node, obtaining a recursive query result corresponding to the accessed node; obtaining the call chain parsing result of the current traversing node according to the recursive query result.

7. The method of claim 6, wherein, The method further comprises: If the return value is empty, and it is determined that the visitor node is located in the assignment dictionary, and the visited node in the current traversal node belongs to a variable node, obtaining a variable value corresponding to the visitor node based on the assignment dictionary, if the return value is not empty, and it is determined that the visitor node is not located in the assignment dictionary, and the visited node in the current traversal node belongs to a variable node, obtaining a variable value corresponding to the visitor node based on the current traversal node; obtaining a call chain analysis result of the current traversal node according to the variable value corresponding to the visitor node.

8. A code file parsing apparatus characterized by comprising: The apparatus comprises: an abstract code tree generation module configured to obtain a code file to be analyzed, and generate an abstract code tree based on the code file; a node type determination module configured to traverse each code node in the abstract code tree, and determine a node type of a current traversal node for each current traversal node; a call chain analysis result obtaining module configured to, when it is determined that the current traversal node meets a function execution condition according to the node type, invoke a node call analysis function, perform call chain analysis on the current traversal node, obtain a call chain analysis result of the current traversal node, and store the call chain analysis result of the current traversal node in an assignment dictionary; a call chain list obtaining module configured to, when all code nodes in the abstract code tree are traversed, obtain a call chain list corresponding to the code file according to the assignment dictionary. 9.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-8 when the computer program is executed by the processor. The processor executes the computer program to implement the steps of the method in any one of claims 1 to 7.

10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method in any one of claims 1 to 7.

11. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method in any one of claims 1 to 7.