Identifier type determination method and apparatus, electronic device, medium, and program product

By determining identifiers and their context in the target code and using recognition models to identify identifiers of unknown types, union types, and object classes, the problem of low accuracy in Javascript type inference is solved, achieving higher accuracy in identifier type determination and simplified software maintenance.

CN119781748BActive Publication Date: 2025-10-21CHINA UNIONPAY
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411823898.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-11
Publication Date
2025-10-21
Estimated Expiration
2044-12-11

AI Technical Summary

Technical Problem

Existing JavaScript type inference methods have low accuracy when determining identifier types, making software maintenance difficult.

Method used

By determining the identifier and its context in the target code, the recognition model is used to identify the identifiers of unknown types, union types and object classes, combined with the identifier type determination of native classes to reduce the false positive rate.

Benefits of technology

The accuracy of identifier type determination is improved, the overall misjudgment rate of identifiers in the code is reduced, and the software maintenance process is simplified.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119781748B_ABST
    Figure CN119781748B_ABST
Patent Text Reader

Abstract

The application provides an identifier type determination method and device, electronic equipment, medium and program product, which can be used in the field of data processing. The method comprises the following steps: determining a plurality of first identifiers and corresponding identifier contexts in target code; determining a first type to which the first identifiers belong according to the identifier contexts; determining a second identifier and a third identifier in each first identifier according to the first type of the first identifier, wherein the first type of the second identifier is an unknown type, a joint type or an object class, and the first type of the third identifier is a native class; identifying the type of each second identifier based on an identification model to obtain a second type to which the second identifier belongs, and the second type is a public library class or a user-defined class. In the application, the determination accuracy of the identifier type is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing, and in particular to a method, device, electronic device, medium, and program product for determining an identifier type. Background Art

[0002] As a dynamic programming language, JavaScript is widely used in browsers and servers due to its flexibility. One of JavaScript's greatest flexibility lies in the fact that identifiers do not require type definitions; their specific types are determined dynamically at runtime. This feature makes type inference, auto-completion, and error checking impossible during coding, significantly complicating the maintenance of large-scale software.

[0003] To address the difficulty of software maintenance, TypeScript was developed. TypeScript is a superset of JavaScript. TypeScript supports identifier type determination and provides a rich set of features such as interfaces, classes, and generics. This type determination undoubtedly reduces software development complexity. However, using this feature requires explicit declaration of the identifier type. An important prerequisite for explicit declaration is type determination, which involves performing type inference on the identifier. This inference can be made regarding whether it is a native class like string or number, or a complex type like a user-defined class.

[0004] In the exemplary technology, the code is input into the model, and the model outputs the type of the identifier. When the type of the identifier output by the model is a probabilistic result, the probabilistic result may be misjudged, resulting in low accuracy in determining the identifier type. Summary of the Invention

[0005] The present application provides a method, device, electronic device, medium and program product for determining an identifier type, which solves the problem of low accuracy in determining the identifier type.

[0006] In a first aspect, the present application provides a method for determining an identifier type, the method comprising:

[0007] determining a plurality of first identifiers and corresponding identifier contexts in the target code;

[0008] determining, according to the identifier context, a first type to which the first identifier belongs;

[0009] determining a second identifier and a third identifier in each of the first identifiers according to a first type of the first identifier, wherein the first type of the second identifier is an unknown type, a union type, or an object class, and the first type of the third identifier is a native class;

[0010] The type of each second identifier is identified based on the identification model to obtain a second type to which the second identifier belongs, where the second type is a public library class or a user-defined class.

[0011] In some embodiments, identifying the type of each second identifier based on the recognition model includes:

[0012] determining a fourth identifier among each of the second identifiers, the fourth identifier being used to indicate the second identifier of an object class;

[0013] determining a frequency of the fourth identifier, the frequency comprising a reference frequency or a definition frequency;

[0014] The second identifier of the unknown type, the second identifier of the joint type, the fourth identifier, and the frequency corresponding to the fourth identifier are input into the recognition model to obtain the second type to which each second identifier belongs.

[0015] In some embodiments, determining the frequency of the fourth identifier includes:

[0016] Constructing a target feature vector corresponding to the fourth identifier, and determining a similarity between the target feature vector and a preset feature vector;

[0017] In response to the similarity being greater than a preset similarity, the frequency associated with the identifier corresponding to the preset feature vector is used as the frequency of the fourth identifier.

[0018] In some embodiments, determining a plurality of first identifiers and corresponding identifier contexts in the target code includes:

[0019] Parsing the target code to obtain an abstract syntax tree;

[0020] A first identifier is extracted from the abstract syntax tree, and an identifier context of the first identifier is constructed according to a statement or expression corresponding to the first identifier in the abstract syntax tree.

[0021] In some embodiments, constructing an identifier context for the first identifier according to a statement corresponding to the first identifier in the abstract syntax tree includes:

[0022] In response to the statement corresponding to the first identifier in the abstract syntax tree being a declaration statement, obtaining a character located to the left of the first identifier in the abstract syntax tree;

[0023] In response to the character on the right side of the first identifier being a constant value or a single variable, an identifier context corresponding to the first identifier is constructed according to the character on the left side and the character on the right side.

[0024] In some embodiments, after obtaining the character located to the left of the first identifier, the method further includes:

[0025] In response to the character on the right side of the first identifier not being a constant value and not being a single variable, constructing an identifier context corresponding to the first identifier based on the character on the left side

[0026] In some embodiments, constructing an identifier context for the first identifier according to an expression corresponding to the first identifier in the abstract syntax tree includes:

[0027] In response to the expression corresponding to the first identifier in the abstract syntax tree being an object expression or an index expression, obtaining a root function corresponding to the first identifier;

[0028] An identifier context corresponding to the first identifier is constructed according to the root function.

[0029] In some embodiments, determining the first type to which the first identifier belongs based on the identifier context includes:

[0030] In response to the identifier context containing a field indicating an object fetch operation, the object class is determined to be the first type of the first identifier.

[0031] In some embodiments, determining the first type to which the first identifier belongs based on the identifier context includes:

[0032] In response to the identifier context containing a field representing a data value operation, determining the native class as a first type to which the first identifier belongs;

[0033] In response to the identifier context containing a field representing an assignment operation, determining an assignment object according to the field of the assignment operation;

[0034] According to the type of the assignment object, a first type to which the first identifier belongs is determined.

[0035] In some embodiments, determining the first type to which the first identifier belongs according to the type to which the assignment object belongs includes:

[0036] In response to the type of the assignment object being a single type, determining the type of the assignment object to be the first type to which the first identifier belongs;

[0037] In response to the assignment object belonging to multiple types, determining the union type as the first type to which the first identifier belongs;

[0038] In response to the type of the assignment object being an unknown type, it is determined that the first type to which the first identifier belongs is an unknown type.

[0039] In some embodiments, before identifying the type of each second identifier based on the recognition model, the method further includes:

[0040] Acquire a plurality of training samples, wherein each of the training samples includes a training identifier and a label, wherein the label is used to indicate whether the training identifier is a user-defined class or a public library class;

[0041] The preset model is trained according to each of the training samples to obtain the recognition type.

[0042] In a second aspect, the present application provides an identifier type determination device, comprising:

[0043] A first determining module, configured to determine a plurality of first identifiers and corresponding identifier contexts in the target code;

[0044] a second determining module, configured to determine a first type to which the first identifier belongs according to the identifier context;

[0045] a third determining module, configured to determine a second identifier and a third identifier from each of the first identifiers according to a first type of the first identifier, wherein the first type of the second identifier is an unknown type, a union type, or an object class, and the first type of the third identifier is a native class;

[0046] The identification module is used to identify the type of each second identifier based on the identification model to obtain the second type to which the second identifier belongs, where the second type is a public library class or a user-defined class.

[0047] In a third aspect, the present application provides an electronic device, comprising: a processor, and a memory and a communication interface communicatively connected to the processor;

[0048] The communication interface is used to communicate with other communication devices;

[0049] The memory is used to store computer-executable instructions;

[0050] The processor is configured to execute the computer-executable instructions stored in the memory to implement the identifier type determination method provided in the first aspect.

[0051] In a fourth aspect, the present application provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are executed by a processor, the identifier type determination method provided in the first aspect is implemented.

[0052] In a fifth aspect, the present application provides a computer program product, comprising a computer program, which, when executed by a processor, implements the identifier type determination method provided in the first aspect.

[0053] The identifier type determination method, device, electronic device, medium and program product provided in the present application first determine the identification class of the native class through the identifier context corresponding to the identifier, and for identifiers of unknown types, object classes, and union types that are difficult to identify as specific types, they are identified through a model. Since there is no misjudgment of the simple native type, the overall misjudgment rate of identifiers in the code is reduced, thereby improving the accuracy of determining the identifier type. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0055] Figure 1 A schematic diagram of the scenarios involved in the identifier type determination method of this application;

[0056] Figure 2 Schematic diagram of the steps of the method for determining the identifier type provided in the embodiment of the present application Figure 1 ;

[0057] Figure 3 Schematic diagram of the steps of the method for determining the identifier type provided in the embodiment of the present application Figure 2 ;

[0058] Figure 4 Schematic diagram of the steps of the method for determining the identifier type provided in the embodiment of the present application Figure 3 ;

[0059] Figure 5 Schematic diagram of the steps of the method for determining the identifier type provided in the embodiment of the present application Figure 4 ;

[0060] Figure 6 Schematic diagram of the steps of the method for determining the identifier type provided in the embodiment of the present application Figure 5 ;

[0061] Figure 7 A schematic diagram of a program module of an identifier type determination device provided in an embodiment of the present application;

[0062] Figure 8 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application.

[0063] The above drawings illustrate specific embodiments of the present application, which will be described in more detail below. These drawings and the textual description are not intended to limit the scope of the present application in any way, but rather to illustrate the concepts of the present application to those skilled in the art by reference to specific embodiments. DETAILED DESCRIPTION

[0064] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application. In addition, although the disclosure in this application is introduced according to one or several exemplary examples, it should be understood that each aspect of these disclosures can also constitute a complete implementation method separately.

[0065] It should be noted that the brief descriptions of terms in this application are only for the purpose of facilitating the understanding of the embodiments described below, and are not intended to limit the embodiments of this application. Unless otherwise specified, these terms should be understood according to their ordinary and usual meanings.

[0066] In addition, the terms "comprises" and "comprising" and any variations thereof are intended to cover but not exclude inclusion, for example, a product or device comprising a list of components is not necessarily limited to those components expressly listed but may include other components not expressly listed or inherent to such product or device.

[0067] The term "module" used in the embodiments of this application refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic or combination of hardware and / or software code that can perform the functions associated with the component.

[0068] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0069] As a dynamic programming language, JavaScript is widely used in browsers and servers due to its flexibility. One of JavaScript's greatest flexibility lies in the fact that identifiers do not require type definitions; their specific types are determined dynamically at runtime. This feature makes type inference, auto-completion, and error checking impossible during coding, significantly complicating the maintenance of large-scale software.

[0070] To address the difficulty of software maintenance, TypeScript was developed. TypeScript is a superset of JavaScript. TypeScript supports identifier type determination and provides a rich set of features such as interfaces, classes, and generics. This type determination undoubtedly reduces software development complexity. However, using this feature requires explicit declaration of the identifier type. An important prerequisite for explicit declaration is type determination, which involves performing type inference on the identifier. This inference can be made regarding whether it is a native class like string or number, or a complex type like a user-defined class.

[0071] The inventors of this application have discovered that when a code is input into a model, the type of the identifier output by the model is obtained. When the type of the identifier output by the model is a probabilistic result, the probabilistic result may be misjudged, resulting in low accuracy in determining the identifier type.

[0072] Therefore, the inventors of the present application came up with the idea of ​​first determining the identification class of the native class through the identifier context corresponding to the identifier, and for identifiers of unknown types, object classes, and union types that are difficult to identify as specific types, they are identified through a model. Since there is no misjudgment of the simple native type, the overall misjudgment rate of identifiers in the code is reduced, thereby improving the accuracy of determining the identifier type.

[0073] Reference Figure 1 , Figure 1 Schematic diagram of the application scenario of the identifier type determination method of the present application. The identifier type determination device 100 obtains the target code, and obtains the first identifier and the corresponding identifier context in the target code. The identifier type determination device 100 determines the first type to which the first identifier belongs based on the identifier context, and determines the third identifier of the native class in each first identifier based on the first type, and determines the second identifier of the unknown type, union type and object class. A recognition model is provided in the identifier type determination device 100, and the second identifier of complex types such as unknown type, union type and object class is identified by the recognition model, thereby determining the second type of each second identifier, and the second type is a public library class or a user-defined class. The device outputs the first type of the third identifier and the second type of the second identifier.

[0074] The following Figure 1The technical solutions shown in this application are described in detail with reference to specific embodiments. It should be noted that the following embodiments can exist independently or in combination with each other, and the same or similar contents will not be repeated in different embodiments.

[0075] Reference Figure 2 , Figure 2 Schematic diagram of the process of the identifier type determination method provided in the embodiment of this application Figure 1 , the identifier type determination method includes:

[0076] Step S201: determining a plurality of first identifiers and corresponding identifier contexts in the target code.

[0077] In this embodiment, the execution subject is an identifier type determination device. For ease of description, the term "device" is used below to refer to the identifier type determination device. The device can be a server or a terminal device with an identifier type determination function.

[0078] The device obtains the target code. The target code can be input by the user, that is, the user inputs the code file into the device, and the device obtains the target code.

[0079] After obtaining the target code, the apparatus determines multiple identifiers in the target code, defining the identifiers as first identifiers. An identifier is a name used in a programming language to identify a variable, function, class, object, or other programming element. After obtaining each first identifier, the apparatus determines an identifier context corresponding to the first identifier in the target code.

[0080] Exemplarily, the device inputs the target code into the construct() function, that is, into the brackets of the function, to output each first identifier and the corresponding identifier context. For example, the device inputs the target code into the construct() function, uses a code parsing tool to obtain the data stream in the output information of the construct() function, and constructs the identifier context based on the data stream.

[0081] Step S202: Determine the first type to which the first identifier belongs according to the identifier context.

[0082] After the identifier context is determined, the first type to which the first identifier belongs is determined based on the identifier context.

[0083] In one example, the device determines a dependency from an identifier and uses the dependency to determine the type of the first identifier. For example, if the first identifier is x and the dependency determined from the identifier context is x->a, and a is of type number, then the type of the first identifier x is also determined to be number, which belongs to a native class. Native classes also include string, boolean, and function types.

[0084] In another example, the identifier context is input into the parentheses of the infer() function, and the output is the first type of the first identifier corresponding to the identifier context. The first type includes string, number, boolean, function, object, UNKNOWN, and UNION. String, number, boolean, and function are primitive classes, simple types that do not require clarification. Object is an object class, UNKNOWN is an unknown type, and UNION is a union type. Object, UNKNOWN, and UNION are complex types that require further clarification.

[0085] In a sub-example, when the infer() function recognizes that the identifier context contains a field representing an object retrieval operation, it returns object, that is, the object class is determined to be the first type of the first identifier corresponding to the identifier context.

[0086] In another sub-example, when the infer() function identifies that the identifier context contains a field representing a data value operation, it returns string, thus identifying the native class as the first type of the first identifier. Furthermore, after obtaining the field representing the data value operation, it parses the field and returns string if the field represents a string concatenation operation.

[0087] In another sub-example, the Dangdang infer() function recognizes that the identifier context contains a field that represents an assignment operation, determines the assignment object based on the field of the assignment operation, and determines the first type to which the first identifier belongs based on the type to which the assignment object belongs. Exemplarily, when the type to which the assignment object belongs is a single type, the type to which the assignment type belongs is determined as the first type to which the first identifier belongs. For example, when the assignment object is a number, string, or object, the number, string, or object returned is used as the first type of the first identifier. When the type to which the assignment object belongs is multiple types, that is, there are multiple types to which the assignment object belongs, UNION is returned, that is, the first type to which the first identifier belongs is a union type. When the type of the assignment object cannot be determined, the type to which the assignment object belongs is an unknown type, that is, the unknown type is determined as the first type to which the first identifier belongs.

[0088] Step S203 , determining a second identifier and a third identifier in each first identifier according to the first type of the first identifier, wherein the first type of the second identifier is an unknown type, a union type or an object class, and the first type of the third identifier is a native class.

[0089] After the device determines the first type to which each first identifier belongs, it needs to classify the first identifiers of unknown type, joint type and object class again.

[0090] Exemplarily, the device determines the second identifier and the third identifier in each first identifier based on the first type of each first identifier, wherein the first type of the second identifier is an unknown type, a union type, or an object class, and the third identifier is a first identifier of a native class.

[0091] Step S204 : Identify the type of each second identifier based on the identification model to obtain the second type to which the second identifier belongs, where the second type is a public library class or a user-defined class.

[0092] The device is provided with an identification model. The device identifies the type of each second identifier through the identification model to obtain the second type to which the second identifier belongs. The second type is a public library class or a user-defined class.

[0093] The recognition model is provided with a bidirectional recurrent neural network, which can process the identifier context well. The encoder EnCoder and decoder DeCoder of the bidirectional recurrent network can respectively encode and decode the identifier, thereby better identifying the second type to which the second identifier belongs.

[0094] The device obtains multiple training samples, each of which includes a training identifier and a label. The label is used to indicate whether the training identifier is a user-defined class or a public library class. The device trains a preset model based on each training sample to obtain a recognition model. The specific training process of the recognition model is as follows:

[0095] 1. Data processing, obtaining training identifiers and corresponding types, which are public library classes or user-defined classes. The device downloads TypeScript files of multiple open source projects from the distributed platform, traverses each TypeScript file, and extracts the identifiers and corresponding types. When extracting identifiers, it is represented by {project name_path name_identifier name}; when extracting types, it contains two forms, declare:{type} and define:{type}, to distinguish between declarations and definitions. Save identifiers and types to different files respectively. Since identifiers include not only variables but also program keywords, the types corresponding to program keywords are set to a special "O".

[0096] 2. Clear the extracted types and remove the types defined in the original file to facilitate training and verification. When the identifier is followed by a ":", remove the ":", that is, remove the type after the colon, thereby removing the type.

[0097] 3. Process the extracted identifier types, removing the declare and define prefixes from the type. Specifically, if the type is a native class, simply remove the declare; if the type is a non-native class, perform type replacement using the classification methods for public library classes and user-defined classes. For example, determine the identifier's frequency. When the identifier's reference frequency exceeds a first threshold, the identifier's type is determined to be a public library class; when the identifier's definition frequency exceeds a second threshold, the identifier's type is determined to be a user-defined class.

[0098] 4. Code representation. This facilitates subsequent model training on a single code file at a time. Previously processed identifier files are extracted sequentially according to the {project name_path name} dimension to form a complete code file. The {project name_path name_identifier name} and type files are processed into word vectors to generate training samples.

[0099] 5. Train the model based on each training sample. Specifically, the full dataset is divided into training set, test set, and validation set in a ratio of 8:1:1. The input data is an identifier in the code, which is converted into a 200-dimensional vector after word vector processing and input into the model. The model consists of two layers, EnCoder and DeCoder, and each layer is a bidirectional RNN network. Each unit in the RNN network is a GRU (Gated Recurrent Unit), with 300 dimensions in the forward direction and 300 dimensions in the reverse direction. The vector output by DeCoder decoding is subjected to dropout processing to prevent overfitting, and then softmax processing is performed to obtain the type probability distribution. Finally, the cross entropy function is used to calculate the loss, and the network is iteratively updated.

[0100] In this embodiment, by combining code static analysis (identifier context determines native class) and recognition model, more accurate identifier classification results can be obtained; at the same time, the object class is further subdivided into public library classes and user-defined classes at a finer granularity, and the application scenarios are more focused.

[0101] In this embodiment, the identification class of the native class is first determined through the identifier context corresponding to the identifier, and for identifiers of unknown types, object classes, and union types that are difficult to identify as specific types, they are identified through the model. Since there is no misjudgment of the simple native type, the overall misjudgment rate of identifiers in the code is reduced, thereby improving the accuracy of determining the identifier type.

[0102] Reference Figure 3 , Figure 3 Schematic diagram of the process of determining the identifier type for this application Figure 2 ,based on Figure 2 In the illustrated embodiment, step S204 includes:

[0103] Step S301: Determine a fourth identifier from each second identifier, where the fourth identifier is used to indicate the second identifier of the object class.

[0104] In this embodiment, due to the particularity of the object class, it is not possible to directly determine whether the object class is a public library class or a user-defined class. Therefore, it is necessary to obtain the frequency of the first identifier belonging to the object class. The frequency includes reference frequency and definition frequency. The reference frequency is, for example, the number of references or the frequency of references, and the definition frequency is, for example, the number of definitions or the frequency of definitions.

[0105] The apparatus determines a fourth identifier from among the second identifiers, the fourth identifier being the second identifier of the object class.

[0106] Step S302: determining the frequency of the fourth identifier, where the frequency includes a reference frequency or a definition frequency.

[0107] The device determines the frequency of the fourth identifier, which includes a reference frequency or a definition frequency. In one example, the target code is associated with an attachment file, which contains the frequency of each identifier, and the device obtains the frequency corresponding to the fourth identifier from the attachment file.

[0108] In another example, a device stores multiple preset identifiers, each associated with a frequency. The device determines a preset identifier similar to a fourth identifier, and uses the frequency associated with the preset identifier as the frequency of the fourth identifier. Exemplarily, the device constructs a target feature vector corresponding to the fourth identifier and determines the similarity between the target feature vector and a preset feature vector, where the preset feature vector is a feature vector of the preset identifier. When the similarity is greater than a preset similarity, the frequency associated with the preset feature vector corresponding to the preset feature vector is used as the frequency of the fourth identifier. The preset similarity can be any suitable value, for example, a preset similarity of 90%.

[0109] Step S303: input the unknown type second identifier, the joint type second identifier, the fourth identifier, and the frequency corresponding to the fourth identifier into the recognition model to obtain the second type to which each second identifier belongs.

[0110] After determining the frequency of the fourth identifier, the unknown type second identifier, the union type second identifier, the fourth identifier, and the corresponding frequency of the fourth identifier are input into the recognition model to obtain the second type to which each second identifier belongs. The frequency of the fourth identifier is used to assist the recognition model in determining whether the fourth identifier belongs to a user-defined class or a public library class.

[0111] In this embodiment, by determining the frequency of the second identifier of the object class, the recognition model can more accurately determine whether the second identifier of the object class belongs to the public library class or the user-defined class.

[0112] Reference Figure 4 , Figure 4 Schematic diagram of the process of determining the identifier type for this application Figure 3 ,based on Figure 2 In the embodiment shown, step S201 includes:

[0113] Step S401: Parse the target code to obtain an abstract syntax tree.

[0114] In this embodiment, after obtaining the target code, the device parses the target code to obtain an abstract syntax tree, through which the identifier context of the first identifier can be quickly constructed.

[0115] Step S402: extract a first identifier from the abstract syntax tree, and construct an identifier context of the first identifier according to a statement or expression corresponding to the first identifier in the abstract syntax tree.

[0116] After obtaining the abstract syntax tree, the device extracts a first identifier from the abstract syntax tree, for example, using {current function name_identifier} as the first identifier. The device obtains the statement or expression containing the first identifier from the abstract syntax tree, thereby constructing an identifier context for the first identifier through the statement or expression.

[0117] In this embodiment, the device parses the target code to obtain an abstract syntax tree, extracts the first identifier from the abstract syntax tree, and determines the statement or expression corresponding to the first identifier in the abstract syntax tree, thereby quickly constructing the identifier context of the first identifier through the statement or expression.

[0118] Reference Figure 5 , Figure 5 Schematic diagram of the process of determining the identifier type for this application Figure 4 ,based on Figure 4 In the illustrated embodiment, step S402 includes:

[0119] Step S501 : In response to the statement corresponding to the first identifier in the abstract syntax tree being a declaration statement, a character located to the left of the first identifier is obtained in the abstract syntax tree.

[0120] Step S502 : In response to the character on the right side of the first identifier being a fixed value or a single variable, an identifier context corresponding to the first identifier is constructed based on the characters on the left side and the characters on the right side.

[0121] In this embodiment, when the statement corresponding to the first identifier in the abstract syntax tree is a declaration statement, the character to the left of the first identifier is obtained in the declaration statement.

[0122] When the character on the right side of the first identifier in the declaration statement is a constant value or a single variable (single variable), an identifier context corresponding to the first identifier is constructed based on the characters on the left side and the characters on the right side.

[0123] When the characters on the right side of the first identifier in a declaration statement are not a definite value and are not a single variable, the identifier context corresponding to the first identifier is constructed based only on the characters on the left side.

[0124] In this embodiment, when the statement corresponding to the first identifier in the abstract syntax tree is a declaration statement, an identifier context corresponding to the first identifier is constructed based on the characters on the left and right of the first identifier in the abstract syntax tree.

[0125] Reference Figure 6 , Figure 6 Schematic diagram of the process of determining the identifier type for this application Figure 5 ,based on Figure 4 In the illustrated embodiment, step S402 includes:

[0126] Step S601: In response to the expression corresponding to the first identifier in the abstract syntax tree being an object expression or an index expression, a root function corresponding to the first identifier is obtained.

[0127] Step S602: construct an identifier context corresponding to the first identifier according to the root function.

[0128] In this embodiment, when the expression corresponding to the first identifier in the abstract syntax tree is an object expression or an index expression, the device obtains the root function corresponding to the first identifier, thereby constructing an identifier context corresponding to the first identifier using the root function. Exemplarily, the device generates root identifiers corresponding to the object expression and the index expression. Furthermore, the device sets the isAssigned or isIndexed value of the first identifier to true as part of the identifier context.

[0129] In this embodiment, when the expression corresponding to the first identifier in the abstract syntax tree is an object expression or an index expression, an identifier context corresponding to the first identifier is constructed based on the root function.

[0130] Based on the contents described in the above embodiments, an identifier type determination device is also provided in the embodiments of the present application. Figure 7 , Figure 7 This is a schematic diagram of program modules of an identifier type determination device provided in an embodiment of the present application. In some embodiments, the identifier type determination device 700 includes:

[0131] A first determining module 710 is configured to determine a plurality of first identifiers and corresponding identifier contexts in the target code;

[0132] A second determining module 720 is configured to determine a first type to which the first identifier belongs based on the identifier context;

[0133] a third determining module 730 for determining a second identifier and a third identifier from each of the first identifiers based on a first type of the first identifier, wherein the first type of the second identifier is an unknown type, a union type, or an object class, and the first type of the third identifier is a native class;

[0134] The identification module 740 is configured to identify the type of each second identifier based on the identification model to obtain the second type to which the second identifier belongs, where the second type is a public library class or a user-defined class.

[0135] In some embodiments, the identifier type determination device 700 is specifically configured to:

[0136] determining a fourth identifier among the second identifiers, the fourth identifier being used to indicate the second identifier of the object class;

[0137] determining a frequency of the fourth identifier, the frequency comprising a reference frequency or a definition frequency;

[0138] The second identifier of the unknown type, the second identifier of the joint type, the fourth identifier, and the frequency corresponding to the fourth identifier are input into the recognition model to obtain the second type to which each second identifier belongs.

[0139] In some embodiments, the identifier type determination device 700 is specifically configured to:

[0140] constructing a target feature vector corresponding to the fourth identifier, and determining a similarity between the target feature vector and a preset feature vector;

[0141] In response to the similarity being greater than a preset similarity, the frequency associated with the identifier corresponding to the preset feature vector is used as the frequency of the fourth identifier.

[0142] In some embodiments, the identifier type determination device 700 is specifically configured to:

[0143] Parse the target code to get the abstract syntax tree;

[0144] A first identifier is extracted from the abstract syntax tree, and an identifier context of the first identifier is constructed according to a statement or expression corresponding to the first identifier in the abstract syntax tree.

[0145] In some embodiments, the identifier type determination device 700 is specifically configured to:

[0146] In response to the statement corresponding to the first identifier in the abstract syntax tree being a declaration statement, obtaining a character located to the left of the first identifier in the abstract syntax tree;

[0147] In response to the character on the right side of the first identifier being a constant value or a single variable, an identifier context corresponding to the first identifier is constructed based on the characters on the left side and the characters on the right side.

[0148] In some embodiments, the identifier type determination device 700 is specifically configured to:

[0149] In response to the character on the right side of the first identifier being non-constant and non-univariate, construct the identifier context corresponding to the first identifier based on the character on the left side.

[0150] In some embodiments, the identifier type determination device 700 is specifically configured to:

[0151] In response to the expression corresponding to the first identifier in the abstract syntax tree being an object expression or an index expression, obtaining a root function corresponding to the first identifier;

[0152] A corresponding identifier context of the first identifier is constructed according to the root function.

[0153] In some embodiments, the identifier type determination device 700 is specifically configured to:

[0154] In response to the identifier context containing a field indicative of a get object operation, the object class is determined to be a first type of the first identifier.

[0155] In some embodiments, the identifier type determination device 700 is specifically configured to:

[0156] In response to the identifier context containing a field representing a data value operation, determining the native class as a first type to which the first identifier belongs;

[0157] In response to the identifier context containing a field representing an assignment operation, determining an assignment object according to the field of the assignment operation;

[0158] According to the type of the assigned object, a first type to which the first identifier belongs is determined.

[0159] In some embodiments, the identifier type determination device 700 is specifically configured to:

[0160] In response to the type to which the assignment object belongs being a single type, determining the type to which the assignment object belongs to be the first type to which the first identifier belongs;

[0161] In response to the assignment object belonging to multiple types, determining the union type as the first type to which the first identifier belongs;

[0162] In response to the type to which the assignment object belongs being an unknown type, it is determined that the first type to which the first identifier belongs is an unknown type.

[0163] In some embodiments, the identifier type determination device 700 is specifically configured to:

[0164] Acquire multiple training samples, wherein each training sample includes a training identifier and a label, and the label is used to indicate whether the training identifier is a user-defined class or a public library class;

[0165] The preset model is trained according to each training sample to obtain the recognition type.

[0166] It should be noted that, for each step in the identifier type determination method executed by the identifier type determination device, specific reference is made to the above embodiment, which will not be described in detail here.

[0167] Furthermore, based on the contents described in the above embodiments, an electronic device is also provided in an embodiment of the present application, which includes at least one processor, and a communication interface and a memory to which the processor is communicatively connected; wherein the communication interface is used to communicate with other communication devices, and the memory stores computer-executable instructions; the above-mentioned at least one processor executes the computer-executable instructions stored in the memory to implement the various steps in the identifier type determination method described in the above embodiments.

[0168] In order to better understand the embodiments of the present application, refer to Figure 8 , Figure 8 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application.

[0169] like Figure 8 As shown, the electronic device 800 of this embodiment includes: a processor 801, a memory 802, and a communication interface 804; wherein:

[0170] Memory 802, for storing computer-executable instructions;

[0171] The communication interface 804 is used to communicate with other communication devices;

[0172] The processor 801 is configured to execute computer-executable instructions stored in the memory to implement the various steps of the query optimization method described in the above embodiment.

[0173] Optionally, the memory 802 may be independent or integrated with the processor 801 .

[0174] When the memory 802 is independently provided, the device further includes a bus 803 for connecting the memory 802 , the communication interface 804 and the processor 801 .

[0175] An embodiment of the present application provides a computer-readable storage medium, which stores computer-executable instructions. When a processor executes the computer-executable instructions, the various steps in the identifier type determination method described in the above embodiment are implemented.

[0176] An embodiment of the present application provides a computer program product, including a computer program. When the computer program is executed by a processor, the computer program implements the various steps of the identifier type determination method described in the above embodiment.

[0177] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of modules is only a logical function division. In actual implementation, there may be other division methods, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interface, device or module, which can be electrical, mechanical or other forms.

[0178] Modules described as separate components may or may not be physically separate, and components shown as modules may or may not be physical units, that is, they may be located in one place or distributed across multiple network elements. Some or all of these modules may be selected to achieve the purpose of this embodiment based on actual needs.

[0179] In addition, the functional modules in the various embodiments of the present application may be integrated into a single processing unit, or each module may exist physically separately, or two or more modules may be integrated into a single unit. The above-mentioned modules may be implemented in the form of hardware or hardware plus software functional units.

[0180] The above-mentioned integrated module implemented in the form of a software functional module can be stored in a computer-readable storage medium. The above-mentioned software functional module is stored in a storage medium and includes a number of instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) or a processor to perform some steps of the methods of various embodiments of the present application.

[0181] It should be understood that the processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the application may be directly implemented by a hardware processor or implemented by a combination of hardware and software modules in the processor.

[0182] The memory may include high-speed memory and may also include non-volatile storage, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk.

[0183] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus. Buses can be classified into address buses, data buses, and control buses. For ease of illustration, the buses in the drawings of this application are not limited to just one bus or just one type of bus.

[0184] The storage medium may be implemented by any type of volatile or non-volatile memory device, or a combination thereof, such as static random access memory, electrically erasable programmable read-only memory, erasable programmable read-only memory, programmable read-only memory, read-only memory, magnetic storage, flash memory, magnetic disk, or optical disk. The storage medium may be any available medium that can be accessed by a general-purpose or special-purpose computer.

[0185] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some or all of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for determining an identifier type, characterized in that: include: determining a plurality of first identifiers and corresponding identifier contexts in the target code; determining, according to the identifier context, a first type to which the first identifier belongs; determining a second identifier and a third identifier in each of the first identifiers according to a first type of the first identifier, wherein the first type of the second identifier is an unknown type, a union type, or an object class, and the first type of the third identifier is a native class; Identify the type of each second identifier based on the identification model to obtain a second type to which the second identifier belongs, where the second type is a public library class or a user-defined class; The identifying the type of each second identifier based on the identification model includes: determining a fourth identifier among each of the second identifiers, the fourth identifier being used to indicate the second identifier of an object class; determining a frequency of the fourth identifier, the frequency comprising a reference frequency or a definition frequency; The second identifier of the unknown type, the second identifier of the joint type, the fourth identifier, and the frequency corresponding to the fourth identifier are input into the recognition model to obtain the second type to which each second identifier belongs.

2. The method for determining the identifier type according to claim 1, wherein: The determining the frequency of the fourth identifier includes: Constructing a target feature vector corresponding to the fourth identifier, and determining a similarity between the target feature vector and a preset feature vector; In response to the similarity being greater than a preset similarity, the frequency associated with the identifier corresponding to the preset feature vector is used as the frequency of the fourth identifier.

3. The method for determining the identifier type according to claim 1, wherein: The determining of a plurality of first identifiers and corresponding identifier contexts in the target code includes: Parsing the target code to obtain an abstract syntax tree; A first identifier is extracted from the abstract syntax tree, and an identifier context of the first identifier is constructed according to a statement or expression corresponding to the first identifier in the abstract syntax tree.

4. The method for determining the identifier type according to claim 3, wherein: The constructing an identifier context of the first identifier according to a statement corresponding to the first identifier in the abstract syntax tree includes: In response to the statement corresponding to the first identifier in the abstract syntax tree being a declaration statement, obtaining a character located to the left of the first identifier in the abstract syntax tree; In response to the character on the right side of the first identifier being a constant value or a single variable, an identifier context corresponding to the first identifier is constructed according to the character on the left side and the character on the right side.

5. The method for determining the identifier type according to claim 4, wherein: After obtaining the character located to the left of the first identifier, the method further includes: In response to the character on the right side of the first identifier not being a constant value and not being a single variable, an identifier context corresponding to the first identifier is constructed according to the character on the left side.

6. The method for determining the identifier type according to claim 3, wherein: The constructing an identifier context of the first identifier according to an expression corresponding to the first identifier in the abstract syntax tree includes: In response to the expression corresponding to the first identifier in the abstract syntax tree being an object expression or an index expression, obtaining a root function corresponding to the first identifier; An identifier context corresponding to the first identifier is constructed according to the root function.

7. The method for determining the identifier type according to claim 1, wherein: The determining, according to the identifier context, the first type to which the first identifier belongs includes: In response to the identifier context containing a field indicating an object fetch operation, the object class is determined to be the first type of the first identifier.

8. The method for determining the identifier type according to claim 1, wherein: The determining, according to the identifier context, the first type to which the first identifier belongs includes: In response to the identifier context containing a field representing a data value operation, determining the native class as a first type to which the first identifier belongs; In response to the identifier context containing a field representing an assignment operation, determining an assignment object according to the field of the assignment operation; According to the type of the assignment object, a first type to which the first identifier belongs is determined.

9. The method for determining the identifier type according to claim 8, wherein: The determining, according to the type of the assignment object, the first type to which the first identifier belongs, includes: In response to the type of the assignment object being a single type, determining the type of the assignment object to be the first type to which the first identifier belongs; In response to the assignment object belonging to multiple types, determining the union type as the first type to which the first identifier belongs; In response to the type of the assignment object being an unknown type, it is determined that the first type to which the first identifier belongs is an unknown type.

10. The method for determining the identifier type according to any one of claims 1 to 9, characterized in that: Before identifying the type of each second identifier based on the recognition model, the method further includes: Acquire a plurality of training samples, wherein each of the training samples includes a training identifier and a label, wherein the label is used to indicate whether the training identifier is a user-defined class or a public library class; The preset model is trained according to each of the training samples to obtain the recognition model.

11. An identifier type determination device, characterized in that: include: A first determining module, configured to determine a plurality of first identifiers and corresponding identifier contexts in the target code; a second determining module, configured to determine a first type to which the first identifier belongs according to the identifier context; a third determining module, configured to determine a second identifier and a third identifier from each of the first identifiers according to a first type of the first identifier, wherein the first type of the second identifier is an unknown type, a union type, or an object class, and the first type of the third identifier is a native class; an identification module, configured to identify the type of each second identifier based on a recognition model, and obtain a second type to which the second identifier belongs, where the second type is a public library class or a user-defined class; The identifier type determination device is specifically used to: determining a fourth identifier among each of the second identifiers, the fourth identifier being used to indicate the second identifier of an object class; determining a frequency of the fourth identifier, the frequency comprising a reference frequency or a definition frequency; The second identifier of the unknown type, the second identifier of the joint type, the fourth identifier, and the frequency corresponding to the fourth identifier are input into the recognition model to obtain the second type to which each second identifier belongs.

12. An electronic device, characterized in that: include: a processor, and a memory and a communication interface communicatively connected to the processor; The communication interface is used to communicate with other communication devices; The memory is used to store computer-executable instructions; The processor is configured to execute the computer-executable instructions stored in the memory to implement the identifier type determination method according to any one of claims 1 to 10.

13. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, the method for determining the identifier type according to any one of claims 1 to 10 is implemented.

14. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the method for determining the identifier type according to any one of claims 1 to 10 is implemented.

Citation Information

Patent Citations

  • Intelligent contract code completion method based on deep neural network and global cache

    CN118092889A