Code cutting method and device, electronic equipment and program product
By managing macrogroup status and type through configuration files and dynamically selecting pruning strategies, the problem of low code pruning efficiency in existing technologies is solved, the correctness and reliability of code pruning are achieved, and pruning efficiency is improved.
Patent Information
- Application Number
- CN202511012883.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-22
- Publication Date
- 2025-11-07
AI Technical Summary
Existing code trimming methods are inefficient, resulting in residual conditional compilation instructions, which compromise code readability and maintainability, and are difficult to adapt to multi-configuration scenarios.
The configuration file manages the state and type of macro groups, dynamically selects pruning strategies, and updates the code lines of macro groups, including code analysis and modification, to ensure the correctness and reliability of the pruned code.
It improves the efficiency of code trimming, avoids syntax errors or logical omissions caused by simple macro removal, and ensures the correctness and reliability of the trimmed code.
Smart Images

Figure CN120909641A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the computer field, and in particular to a code pruning method and device, electronic equipment and program product. BACKGROUND
[0002] In the current software industry, code authorization has become a core link of software distribution, and a large amount of code can be shared and reused.
[0003] The current code pruning method relies on a compiler preprocessing module, copies the source code to generate a copy, extracts conditional compilation information through the compiler, modifies the macro value in the copy according to the configuration file, compares the preprocessed file with the original file, marks the valid code line number, and deletes the code corresponding to the invalid line number.
[0004] In the above code pruning process, only line-level physical deletion is supported, which results in residual conditional compilation instructions, destroys the readability and maintainability of the code, and is difficult to adapt to multiple configuration scenarios, resulting in low code pruning efficiency. SUMMARY
[0005] The present application provides a code pruning method, device, electronic equipment and program product to solve the technical problem of low code pruning efficiency in the prior art.
[0006] In a first aspect, the present application provides a code pruning method, which comprises:
[0007] obtaining a configuration file and an original code file, the configuration file comprising macro group identifiers of a plurality of macro groups in the original code file and an enabling state corresponding to at least one macro in each macro group;
[0008] determining the macro group types corresponding to the plurality of macro groups according to the configuration file;
[0009] for any one macro group, performing update processing on a plurality of code lines corresponding to the macro group in the original code file according to the macro group type of the macro group and the configuration file, to obtain current codes and current line states corresponding to the plurality of code lines, the update processing comprising at least one of code analysis processing and code modification processing;
[0010] performing pruning processing on the current codes corresponding to the plurality of macro groups according to the plurality of current line states corresponding to the plurality of macro groups, to obtain a target code file.
[0011] In this way, the macro group state and type are managed by the configuration file, the pruning strategy is dynamically selected based on the macro group type and the configured enabling state, the syntax errors or logical omissions that may be caused by simple macro removal are avoided, the correctness and reliability of the pruned code are ensured, and the code pruning efficiency is improved.
[0012] Optionally, the method as described above, according to the macro group type of the macro group and the configuration file, the original code file in the macro group corresponding to a plurality of code lines are updated to obtain the current code and the current line state corresponding to the plurality of code lines, comprising:
[0013] Determine whether the macro group type of the macro group is the first type;
[0014] If yes, the original code of the plurality of code lines in the original code file is determined as the current code of the plurality of code lines, and according to the configuration file, the plurality of code lines corresponding to the macro group in the original code file are processed to determine the current line state corresponding to the plurality of code lines respectively;
[0015] If not, according to the configuration file, the plurality of code lines corresponding to the macro group in the original code file are processed to determine the current code and the current line state corresponding to the plurality of code lines respectively.
[0016] In this way, the pruning strategy is dynamically selected based on the macro group type and the enabled state of the configuration, avoiding syntax errors or logical omissions that may be caused by simple macro removal, ensuring the correctness and reliability of the pruned code, and improving the code pruning efficiency.
[0017] Optionally, the method as described above, according to the configuration file, the plurality of code lines corresponding to the macro group in the original code file are processed to determine the current line state corresponding to the plurality of code lines respectively, comprising:
[0018] The configuration file is parsed to obtain at least one macro identifier corresponding to the macro group and the enabled state corresponding to the macro identifier;
[0019] According to the at least one macro identifier, at least one target macro is determined in the plurality of code lines;
[0020] According to the enabled state corresponding to the at least one macro identifier, the current line state of the plurality of code lines corresponding to the at least one target macro is determined respectively.
[0021] In this way, in the macro group in which only one macro is enabled, only the current line state of the plurality of code lines in the macro group needs to be modified, ensuring the correctness and reliability of the pruned code and improving the code pruning efficiency.
[0022] Optionally, the method as described above, according to the enabled state corresponding to the at least one macro identifier, the current line state of the plurality of code lines corresponding to the at least one target macro is determined respectively, comprising:
[0023] determining, according to the at least one macro identifier, a current line state of at least one target macro corresponding to the at least one macro identifier in the plurality of code lines;
[0024] For any one instruction line, determining a code segment corresponding to the instruction line, when the current line state of the instruction line is a true state, determining a current line state of the code segment as the true state, and updating the current line state of the instruction line as a false state, and when the current line state of the instruction line is the false state, determining the current line state of the code segment as the false state.
[0025] In this way, the current line state of the instruction line can be updated according to the current line state of the code segment, invalid instruction lines are avoided, the code structure is optimized, the correctness and reliability of the cropped code are ensured, and the code cropping efficiency is improved.
[0026] Optionally, the method described above, according to the configuration file, performing code analysis processing and code modification processing on the plurality of code lines corresponding to the macro group in the original code file, obtaining current codes and current line states corresponding to the plurality of code lines respectively, comprises:
[0027] performing parsing processing on the configuration file to obtain at least one macro identifier corresponding to the macro group and an enabling state corresponding to the macro identifier;
[0028] determining, according to the at least one macro identifier, at least one target macro in the plurality of code lines;
[0029] determining, according to the enabling state corresponding to the at least one macro identifier, current line states of the plurality of code lines corresponding to the at least one target macro respectively, and modifying original codes corresponding to the at least one target macro respectively to determine current codes corresponding to the plurality of code lines respectively.
[0030] In this way, in the macro group in which a plurality of macros are enabled, the current line states of the plurality of code lines in the macro group need to be determined, and the corresponding instruction lines need to be modified to eliminate invalid nested levels, which avoids syntax errors or logical omissions that may be caused by simple macro removal, ensures the correctness and reliability of the cropped code, and improves the code cropping efficiency.
[0031] Optionally, the method described above, according to the enabling state corresponding to the at least one macro identifier, determining current line states of the plurality of code lines corresponding to the at least one target macro respectively, and modifying original codes corresponding to the at least one target macro respectively to determine current codes corresponding to the plurality of code lines respectively, comprises:
[0032] determining, in the plurality of code lines, instruction lines respectively corresponding to a plurality of target macros according to the corresponding enabling state of the at least one macro identifier, and a current line state corresponding to the instruction lines;
[0033] modifying the original code respectively corresponding to the plurality of instruction lines according to the current line state corresponding to the plurality of instruction lines to obtain updated code respectively corresponding to the plurality of code lines;
[0034] determining a code segment corresponding to the instruction line and a line type corresponding to the instruction line for any one instruction line;
[0035] when the current line state of the instruction line is a true state, determining the current line state corresponding to the code segment as the true state, and modifying the updated code corresponding to the instruction line according to the line type and the current line state of the instruction line to determine current code of the plurality of code lines corresponding to the instruction line;
[0036] when the current line state of the instruction line is a false state, determining the current line state corresponding to the code segment as the false state, and determining the updated code corresponding to the plurality of code lines as the current code corresponding to the plurality of code lines.
[0037] In this way, the pruning strategy is dynamically selected based on the macro group type and the enabling state of the configuration, avoiding syntax errors or logical omissions that may be caused by simple macro removal, ensuring the correctness and reliability of the pruned code, and improving the code pruning efficiency.
[0038] Optionally, in the method described above, modifying the updated code corresponding to the instruction line according to the line type and the current line state of the instruction line to determine the current code of the plurality of code lines corresponding to the instruction line comprises:
[0039] if the line type is a first line type, determining whether an adjacent previous instruction line in the instruction line is an instruction line with a second line type and a false state, and if so, modifying the updated code corresponding to the instruction line according to the code corresponding to the second line type to determine the current code of the plurality of code lines, the current code including the code of the instruction line and the code corresponding to the code segment;
[0040] if the line type is a third line type, determining whether the line state respectively corresponding to the instruction lines other than the instruction line in the plurality of instruction lines is a false state, and if so, modifying the updated code corresponding to the instruction line to be empty to determine the current code of the plurality of code lines, the current code including the code corresponding to the code segment.
[0041] In this way, the invalid nested levels are eliminated, the syntax errors or logical defects caused by the simple macro removal are avoided, the correctness and reliability of the cropped code are ensured, and the code cropping efficiency is improved.
[0042] In a second aspect, the present application provides a code cropping device, the device comprising:
[0043] An acquisition module is configured to acquire a configuration file and an original code file, wherein the configuration file comprises macro group identifiers of a plurality of macro groups in the original code file and an enabling state corresponding to at least one macro in each macro group.
[0044] A determination module is configured to determine macro group types corresponding to the plurality of macro groups according to the configuration file.
[0045] For any one macro group, an updating module is configured to perform updating processing on a plurality of code lines corresponding to the macro group in the original code file according to the macro group type of the macro group and the configuration file, to obtain current codes and current line states corresponding to the plurality of code lines, respectively, wherein the updating processing comprises at least one of code analysis processing and code modification processing.
[0046] A cropping module is configured to perform cropping processing on a plurality of current codes corresponding to the plurality of macro groups according to a plurality of current line states corresponding to the plurality of macro groups, to obtain a target code file.
[0047] Optionally, the updating module is specifically configured to:
[0048] determine whether the macro group type of the macro group is a first type;
[0049] If yes, the original codes of the plurality of code lines in the original code file are determined as the current codes of the plurality of code lines, and code analysis processing is performed on the plurality of code lines corresponding to the macro group in the original code file according to the configuration file, to determine the current line states corresponding to the plurality of code lines, respectively.
[0050] If no, code analysis processing and code modification processing are performed on the plurality of code lines corresponding to the macro group in the original code file according to the configuration file, to obtain the current codes and the current line states corresponding to the plurality of code lines, respectively.
[0051] Optionally, the updating module is specifically configured to:
[0052] perform parsing processing on the configuration file, to obtain at least one macro identifier corresponding to the macro group and an enabling state corresponding to the macro identifier;
[0053] determine at least one target macro in the plurality of code lines according to the at least one macro identifier;
[0054] determine, according to the enable state corresponding to the at least one macro identifier, current line states of a plurality of code lines corresponding to the at least one target macro respectively.
[0055] Optionally, the updating module is specifically configured to:
[0056] determine, according to the enable state corresponding to the at least one macro identifier, instruction lines corresponding to the at least one target macro respectively in the plurality of code lines, and current line states corresponding to the instruction lines;
[0057] For any one instruction line, determine a code segment corresponding to the instruction line, determine a current line state corresponding to the code segment as a true state when the current line state of the instruction line is the true state, and update the current line state of the instruction line as a false state, and determine the current line state corresponding to the code segment as the false state when the current line state of the instruction line is the false state.
[0058] Optionally, the updating module is specifically configured to:
[0059] perform parsing processing on the configuration file to obtain at least one macro identifier corresponding to the macro group and an enable state corresponding to the macro identifier;
[0060] determine, according to the at least one macro identifier, at least one target macro in the plurality of code lines;
[0061] determine, according to the enable state corresponding to the at least one macro identifier, current line states of a plurality of code lines corresponding to the at least one target macro respectively, and modify original codes corresponding to the at least one target macro respectively to determine current codes corresponding to the plurality of code lines respectively.
[0062] Optionally, the updating module is specifically configured to:
[0063] determine, according to the enable state corresponding to the at least one macro identifier, instruction lines corresponding to a plurality of target macros respectively in the plurality of code lines, and current line states corresponding to the instruction lines;
[0064] perform modification processing on original codes corresponding to a plurality of instruction lines respectively according to current line states corresponding to the plurality of instruction lines to obtain updated codes corresponding to the plurality of code lines respectively;
[0065] For any one instruction line, determine a code segment corresponding to the instruction line, and a line type corresponding to the instruction line;
[0066] determining the current line state of the code segment as the true state, and modifying the update code corresponding to the instruction line according to the line type and the current line state of the instruction line, to determine the current code of the plurality of code lines corresponding to the instruction line;
[0067] determining the current line state of the code segment as the false state, and determining the update code corresponding to the plurality of code lines as the current code of the plurality of code lines.
[0068] Optionally, the module as described above, the update module is specifically configured to:
[0069] if the line type is the first line type, determining whether an adjacent previous instruction line in the instruction line is an instruction line with a second line type and a false current line state, if yes, modifying the update code corresponding to the instruction line according to the code corresponding to the second line type, to determine the current code of the plurality of code lines, the current code including the code of the instruction line and the code corresponding to the code segment;
[0070] if the line type is a third line type, determining whether the line states corresponding to the instruction lines other than the instruction line in the plurality of instruction lines are false states, if yes, modifying the update code corresponding to the instruction line as empty, to determine the current code of the plurality of code lines, the current code including the code corresponding to the code segment.
[0071] In a third aspect, the present application provides an electronic device, comprising: a processor, and a memory connected to the processor in communication;
[0072] the memory stores computer execution instructions;
[0073] the processor executes the computer execution instructions stored in the memory, to implement the method of any one of the first aspect.
[0074] In a fourth aspect, the present application provides a computer readable storage medium, the computer readable storage medium stores computer execution instructions, the computer execution instructions are executed by the processor to implement the method of any one of the first aspect.
[0075] In a fifth aspect, the present application provides a computer program product, comprising a computer program, the computer program is executed by the computer to implement the method of any one of the first aspect.
[0076] The code pruning method, device, electronic equipment and program product provided by the application obtain a configuration file and an original code file, the configuration file including macro group identifiers of a plurality of macro groups in the original code file and an enabling state corresponding to at least one macro in each macro group; according to the configuration file, the macro group types corresponding to the plurality of macro groups are determined; for any one macro group, according to the macro group type of the macro group and the configuration file, a plurality of code lines corresponding to the macro group in the original code file are updated to obtain current codes and current line states corresponding to the plurality of code lines, the updating process including at least one of code analysis processing and code modification processing; according to the plurality of current line states corresponding to the plurality of macro groups, the plurality of current codes corresponding to the plurality of macro groups are pruned to obtain a target code file. In this way, the macro group state and type are managed through the configuration file, the pruning strategy is dynamically selected based on the macro group type and the enabling state of the configuration, syntax errors or logical omissions caused by simple macro removal are avoided, the correctness and reliability of the pruned code are ensured, and the code pruning efficiency is improved. BRIEF DESCRIPTION OF DRAWINGS
[0077] The accompanying drawings, which are incorporated herein and form part of the specification, illustrate embodiments consistent with the present application and, together with the description, further serve to explain the principles of the application.
[0078] Figure 1 A structural schematic diagram of a code pruning system provided by an embodiment of the application;
[0079] Figure 2 A flowchart of a code pruning method provided by an embodiment of the application;
[0080] Figure 3 A flowchart of another code pruning method provided by an embodiment of the application;
[0081] Figure 4 A structural schematic diagram of a code pruning device provided by an embodiment of the application;
[0082] Figure 5 A structural schematic diagram of an electronic equipment provided by an embodiment of the application.
[0083] The above-described drawings have shown the specific embodiments of the application, and the following will have a more detailed description. These drawings and textual descriptions are not intended to limit the scope of the concept of the application by any means, but to illustrate the concept of the application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0084] The exemplary embodiments will be described in detail herein with reference to the attached drawings. In the following description, like reference numerals refer to like elements throughout the description. The following exemplary embodiments described herein represent illustrations of apparatuses and methods that are in accordance with some aspects of the present application as detailed in the appended claims. These examples are, of course, merely intended to provide an overview of the methods and apparatuses in accordance with aspects of the present application and are not intended to limit the scope of the application.
[0085] It should be noted that although the terms "first", "second" and the like are used herein to describe various information, the information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. Alternatively, the first information can also be referred to as the second information, and similarly, the second information can also be referred to as the first information without departing from the scope of the present application.
[0086] It should be understood that the terms "comprising", "including", indicate the presence of the previously mentioned features, steps, operations, but do not exclude the presence or addition of one or at least one other feature, step, operation. The terms "and / or" and the like used in the present application can be interpreted as inclusive, or mean any one or any combination. Alternatively, "A and / or B" means "either A; B; A and B". In addition, the character " / " herein generally indicates that the associated objects before and after are in an "or" relationship.
[0087] 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 one or more embodiments of the present specification 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 laws, regulations and standards, and provide corresponding operation portal for user to choose authorization or refusal.
[0088] In the current software industry, code authorization has become the core link of software distribution, and a large amount of code can be shared and reused.
[0089] The current code cutting method depends on the compiler preprocessing module, copies the source code to generate a copy, extracts the conditional compilation information through the compiler, modifies the macro value in the copy according to the configuration file, compares the preprocessed file with the original file, marks the valid code line number, and deletes the code corresponding to the invalid line number.
[0090] In the above code cutting process, only line-level physical deletion is supported, resulting in residual conditional compilation instructions, which destroys the readability and maintainability of the code, and is difficult to adapt to multiple configuration scenarios, resulting in low efficiency of code cutting.
[0091] To solve the above technical problems, the embodiment of the present application provides a code pruning method, a configuration file is used to determine the macro group types corresponding to a plurality of macro groups, for any one macro group, a plurality of code lines of the macro group are updated to obtain current code and current line state, the updating includes at least one of code analysis processing and code modification processing, according to a plurality of current line states corresponding to the plurality of macro groups, a plurality of current codes corresponding to the plurality of macro groups are pruned to obtain a target code file. In this way, the macro group state and type are managed through the configuration file, the pruning strategy is dynamically selected based on the macro group type and the enabled state of the configuration, the syntax error or logic loss caused by simple macro removal is avoided, the correctness and reliability of the pruned code are ensured, and the code pruning efficiency is improved.
[0092] In the following, the code pruning system is described in combination with Figure 1 The architecture of the code pruning system is exemplified.
[0093] Figure 1 The structure diagram of the code pruning system provided by the embodiment of the present application is shown. Please refer to Figure 1 , Figure 1 The code pruning system can include a configuration manager, a source code repository and a code processor.
[0094] The configuration manager, the source code repository and the code processor can be communicatively connected.
[0095] The configuration manager can be used to store and manage the macro definitions and states required by different target devices, platforms or product variants, to generate configuration files based on hardware, product characteristics or user requirements.
[0096] The configuration file can define the macro group identification and the enabled state of the internal macro.
[0097] The configuration manager can include a configuration file database, a configuration editing tool, a version control system and the like.
[0098] The source code repository can be used to store and manage the complete source code of the project.
[0099] The code processor can read the configuration file from the configuration manager, obtain the original code from the source code repository, and update a plurality of code lines of a macro group according to the macro group types corresponding to the plurality of macro groups in the original code, determine the current code and the current line state, prune a plurality of current codes corresponding to the plurality of macro groups according to a plurality of current line states corresponding to the plurality of macro groups, and obtain a target code file.
[0100] The code processor can be a separate processor or a central processor integrated in the code pruning system, which is not limited here.
[0101] The technical solutions of the present application and how the technical solutions of the present application solve the above technical problems will be described in detail below with specific examples. The following specific examples can be combined with each other, and the same or similar concepts or processes can not be repeated in some examples. The embodiments of the present application will be described below with reference to the accompanying drawings.
[0102] The technical solutions shown in the present application will be described in detail below through specific examples. It should be noted that the following examples can exist independently, or can be combined with each other, and the same or similar content will not be repeated in different examples.
[0103] Figure 2 A flowchart of a code pruning method provided by an embodiment of the present application is shown. The execution subject of the embodiment of the present application can be a processor. The processor can be implemented by software, or by a combination of software and hardware. Please refer to Figure 2 The method comprises the following steps:
[0104] S201, obtaining a configuration file and an original code file.
[0105] The configuration file comprises macro group identifiers of a plurality of macro groups in the original code file, and an enabling state corresponding to at least one macro in each macro group.
[0106] The macro group can be a set of logically related preprocessor macro definitions and / or macro conditional compilation instructions.
[0107] The macro group can be used to control a configuration option of a function module, a chip, a hardware adaptation layer, an optional feature, etc., which is not limited herein.
[0108] The macro group identifier can be used to identify the macro group, so that the configuration item in the configuration file is associated with the corresponding macro group code block in the original code.
[0109] For example, the macro group identifier can be CHOPPREFIXCONF_FUNC, and at least one macro can be included in the macro group corresponding to CHOPPREFIXCONF_FUNC, wherein the macro identifiers corresponding to the at least one macro in the macro group are CHOPPREFIXCONF_FUNC_A and CHOPPREFIXCONF_FUNC_B respectively.
[0110] For another example, the macro group identifier can be CHOPPREFIXCONF_CHIP, and at least one macro can be included in the macro group corresponding to CHOPPREFIXCONF_CHIP, wherein the macro identifiers corresponding to the at least one macro in the macro group are CHOPPREFIXCONF_CHIP_A and CHOPPREFIXCONF_CHIP_B respectively.
[0111] The enabled state can include an enabled on state and an enabled off state.
[0112] The on state can be used to indicate that the macro is in an effective state, and the plurality of code lines corresponding to the macro can be reserved.
[0113] The off state can be used to indicate that the macro is in an ineffective state, and the plurality of code lines corresponding to the macro can be pruned.
[0114] For example, assuming that the macro can be CHOPREFIXCONF_AA, the pre-compile condition can be:
[0115]
[0116] The value of CHOPREFIXCONF_AA can indicate the enabled state corresponding to the macro.
[0117] Whether to compile the code block between #if and #endif can be determined by judging the value of the macro CHOPREFIXCONF_AA (non-zero is true, and zero is false).
[0118] For another example, assuming that the macro can be CHOPREFIXCONF_AA, the pre-compile condition can be:
[0119]
[0120] The value of the macro CHOPREFIXCONF_AA can indicate the enabled state corresponding to the macro.
[0121] Only when the macro CHOPREFIXCONF_AA is defined and the value is exactly 1, the code block marked as " / / pre-compile macro logic judgment" between #if and #endif will participate in the compilation; if the macro is not defined, or the value is not equal to 1 after being defined, the code block will not participate in the compilation.
[0122] The present application can support a plurality of pre-compile conditions, which are not limited herein.
[0123] The configuration file can be obtained through a configuration manager, and the original code file can be obtained through a source code repository.
[0124] The user-specified file path can be received through a command line parameter, the configuration file can be obtained according to the file path, and the original code file can be obtained through the source code repository.
[0125] It should be noted that the configuration file and the original code file can be obtained according to any feasible implementation manner, which is not limited in the embodiments of the present application.
[0126] Before the configuration file and the original code file are acquired, the method further includes preprocessing source code in a source code repository through pre-compiled instructions, and the preprocessing of the source code in the source code repository through the pre-compiled instructions can be performed in the following manner: performing classification processing on the source code to obtain a plurality of macro groups, and generating macro group identifiers corresponding to the plurality of macro groups according to a plurality of preset macro definitions.
[0127] In S202, a macro group type corresponding to each of the plurality of macro groups is determined according to the configuration file.
[0128] The macro group type can include a first type and a second type.
[0129] The first type can be used to indicate that only one macro in the macro group is enabled, and the second type can be used to indicate that a plurality of macros in the macro group are enabled.
[0130] The plurality of macro groups can be identified according to the configuration file to determine the macro group type corresponding to each of the plurality of macro groups.
[0131] It should be noted that the macro group type corresponding to each of the plurality of macro groups can be determined according to any feasible implementation manner, and the embodiments of the present application do not limit this.
[0132] In S203, for any one macro group, a plurality of code lines corresponding to the macro group in the original code file are updated according to the macro group type of the macro group and the configuration file to obtain current code and a current line state corresponding to each of the plurality of code lines.
[0133] The update processing includes at least one of code analysis processing and code modification processing.
[0134] The code analysis processing can be used to analyze the current line state corresponding to each of the plurality of code lines.
[0135] The code modification processing can be used to modify the instruction line corresponding to the macro group.
[0136] The current code can include an instruction line and a code segment corresponding to the macro group.
[0137] The current line state can be used to indicate a state corresponding to the code line.
[0138] The current line state can include a true state and a false state.
[0139] The current code and the current line state corresponding to each of the plurality of code lines can be obtained according to any feasible implementation manner, and embodiments of the present application do not limit this.
[0140] It should be noted that the current code and the current line state corresponding to each of the plurality of code lines can be obtained according to any feasible implementation manner, and embodiments of the present application do not limit this.
[0141] S204, according to the plurality of current line states corresponding to the plurality of macro groups, the plurality of current codes corresponding to the plurality of macro groups are processed to obtain a target code file.
[0142] The pruning processing can be used to prune the current code with the false state.
[0143] The target code file can be used to represent a code file obtained by pruning the original code file.
[0144] In the plurality of current line states corresponding to the plurality of macro groups, the plurality of current codes with the false state can be determined, the plurality of current codes with the false state are pruned, and the plurality of current codes with the true state are determined as the target code file.
[0145] It should be noted that the target code file can be obtained according to any feasible implementation manner, and embodiments of the present application do not limit this.
[0146] The code pruning method provided in the embodiment includes the following steps: obtaining a configuration file and an original code file, the configuration file including macro group identifiers of a plurality of macro groups in the original code file and an enabling state corresponding to at least one macro in each macro group; determining macro group types corresponding to the plurality of macro groups according to the configuration file; for any one macro group, according to the macro group type of the macro group and the configuration file, performing update processing on a plurality of code lines corresponding to the macro group in the original code file to obtain current code and a current line state corresponding to each of the plurality of code lines, the update processing including at least one of code analysis processing and code modification processing; and according to the plurality of current line states corresponding to the plurality of macro groups, performing pruning processing on the plurality of current codes corresponding to the plurality of macro groups to obtain a target code file. In this way, the macro group state and type are managed through the configuration file, the pruning strategy is dynamically selected based on the macro group type and the configured enabling state, syntax errors or logical omissions caused by simple macro removal are avoided, the correctness and reliability of the pruned code are ensured, and the code pruning efficiency is improved.
[0147] Below, combined with Figure 3 The process (S203) of updating the multiple code lines corresponding to the macro group in the original code file according to the macro group type of the macro group and the configuration file, and obtaining the current code and the current line state corresponding to the multiple code lines respectively, is explained and described.
[0148] Figure 3 Another flowchart of the code pruning method provided by the embodiment of the present application is provided. Based on the above embodiment, referring to Figure 3 The method comprises the following steps.
[0149] S301, determining whether the macro group type of the macro group is the first type.
[0150] If yes, S302 is executed;
[0151] If no, S306 is executed.
[0152] The macro group type can comprise the first type and the second type.
[0153] There is only one macro in the enabled state in the first type, and there are multiple macros in the enabled state in the second type.
[0154] For example, assuming that the macro CHOPPREFIXCONF_FUNC_A and the macro CHOPPREFIXCONF_FUNC_B are both in the enabled state, it is determined that the macro group type of the macro group is the second type.
[0155] S302, determining the original code of the multiple code lines in the original code file as the current code of the multiple code lines.
[0156] In the case where the macro group type is the first type, the multiple code lines in the original code file are not modified.
[0157] S303, performing parsing processing on the configuration file to obtain at least one macro identifier corresponding to the macro group, and an enabled state corresponding to the macro identifier.
[0158] The macro identifier can be a unique identifier of the macro.
[0159] The enabled state can comprise an enabled state and an enabled-off state.
[0160] The configuration file can be parsed by a preset algorithm to obtain multiple macro groups, at least one macro identifier corresponding to each macro group, and an enabled state corresponding to each macro identifier.
[0161] S304, determining at least one target macro in the multiple code lines according to the at least one macro identifier.
[0162] A target macro can refer to multiple lines of code that are identified by a macro.
[0163] For example, suppose a macro group has multiple lines of code as shown below:
[0164]
[0165] At least one target macro can be:
[0166]
[0167]
[0168] There is at least one macro identifier in multiple lines of code.
[0169] Based on at least one macro identifier in the configuration file, the line containing the macro identifier can be located in multiple lines of code to determine at least one target macro.
[0170] S305. Based on the enable state corresponding to at least one macro identifier, determine the current line state of multiple lines of code corresponding to at least one target macro.
[0171] The current row state can include a true state and a fake state.
[0172] If the enable state corresponding to the macro identifier is enabled, then the current line state of the multiple lines of code corresponding to the target macro can be determined to be true. If the enable state corresponding to the macro identifier is disabled, then the current line state of the multiple lines of code corresponding to the target macro can be determined to be false.
[0173] Optionally, the current line state of multiple lines of code corresponding to at least one target macro can be determined based on the enable state corresponding to at least one macro identifier in the following manner: Based on the enable state corresponding to at least one macro identifier, determine the instruction line corresponding to at least one target macro and the current line state corresponding to the instruction line in the multiple lines of code; for any instruction line, determine the code segment corresponding to the instruction line; when the current line state of the instruction line is true, determine the current line state corresponding to the code segment as true and update the current line state of the instruction line to false; when the current line state of the instruction line is false, determine the current line state corresponding to the code segment as false.
[0174] For example, suppose the target macro is:
[0175]
[0176] In this context, "#if CHOPPREFIXCONF_XXX / / IF compiler macro line" is the instruction line, and " / / IF code segment" is the code segment.
[0177] If the current line state of the instruction line is the true state, the current line state of the code segment corresponding to the macro is determined as the true state, and the current line state of the instruction line is updated as the false state. In this way, in the macro group of the first type, only the code segment needs to be preserved, and the correctness and reliability of the pruned code are ensured.
[0178] For example, assuming that the macro is an IF macro, if the enable state of the IF macro is the enable-on state, the current line state of the code segment corresponding to the IF macro is the true state, and the current line state of the line where the IF macro is located is updated as the false state.
[0179] S306, the configuration file is parsed to obtain a plurality of macro identifiers corresponding to the macro group and an enable state corresponding to the macro identifier.
[0180] The execution process of S306 can refer to the execution process of S303 described above, and will not be described here again.
[0181] S307, according to the plurality of macro identifiers, a plurality of target macros are determined in a plurality of code lines.
[0182] The execution process of S307 can refer to the execution process of S304 described above, and will not be described here again.
[0183] S308, according to the enable state corresponding to the plurality of macro identifiers, an instruction line corresponding to each of the plurality of target macros is determined in the plurality of code lines, and a current line state corresponding to the instruction line is determined.
[0184] According to the plurality of macro identifiers, the instruction line corresponding to each of the plurality of target macros can be determined in the plurality of code lines, and the current line state corresponding to the instruction line can be determined according to the enable state corresponding to the plurality of macro identifiers.
[0185] S309, according to the current line state corresponding to the plurality of instruction lines, the original code corresponding to each of the plurality of instruction lines is modified to obtain updated code corresponding to each of the plurality of code lines.
[0186] At least one target instruction line with the true state can be determined, and the original code of the target instruction line is modified, and the other code lines remain unchanged to obtain updated code corresponding to each of the plurality of code lines.
[0187] Optionally, the original code of the target instruction line can be modified by modifying the original code of the target instruction line to 0.
[0188] S310, for any one instruction line, a code segment corresponding to the instruction line and a line type corresponding to the instruction line are determined.
[0189] The line type can include a first line type, a second line type, a third line type, and the like.
[0190] For example, the first line type can be a line type corresponding to an ELIF compilation macro, the second line type can be a line type corresponding to an IF compilation macro, and the third line type can be a line type corresponding to an ELSE compilation macro.
[0191] For any one instruction line, the instruction line can be parsed and processed to determine the line type corresponding to the instruction line, and the code segment corresponding to the instruction line can be determined according to the instruction line.
[0192] S311, when the current line state of the instruction line is the true state, the current line state corresponding to the code segment is determined as the true state, and the updated code corresponding to the instruction line is modified according to the line type and the current line state of the instruction line, to determine the current code of the plurality of code lines corresponding to the instruction line.
[0193] When the current line state of the instruction line is the true state, the current line state corresponding to the code segment can be determined as the true state, and when the current line state of the instruction line is the true state, the updated code corresponding to the instruction line can be modified according to the line type, and the other code lines remain unchanged, to determine the current code of the plurality of code lines corresponding to the instruction line.
[0194] Optionally, the updated code corresponding to the instruction line can be modified according to the line type and the current line state of the instruction line to determine the current code of the plurality of code lines corresponding to the instruction line in the following manner: if the line type is the first line type, it is determined whether the adjacent previous instruction line in the instruction line is an instruction line with the second line type and the false state, if yes, the updated code corresponding to the instruction line is modified according to the code corresponding to the second line type to determine the current code of the plurality of code lines, and the current code includes the code of the instruction line and the code corresponding to the code segment; if the line type is the third line type, it is determined whether the line state corresponding to the instruction line other than the instruction line in the plurality of instruction lines is the false state, if yes, the updated code corresponding to the instruction line is modified to be empty to determine the current code of the plurality of code lines, and the current code includes the code corresponding to the code segment.
[0195] For example, assuming that the first line type can be a line type corresponding to an ELIF compilation macro, the second line type can be a line type corresponding to an IF compilation macro, it can be checked whether the type of the adjacent previous instruction line is the line type corresponding to the IF compilation macro and the current line state is the false state, if yes, the ELIF compilation macro is changed to the IF compilation macro, i.e., the instruction line of the first line type is changed to the instruction line of the second line type, and the other code lines remain unchanged to determine the current code of the plurality of code lines.
[0196] For example, assuming that the third row type can be the row type corresponding to the ELSE compilation macro, it can be determined whether the row states corresponding to the instruction rows other than the instruction row in the plurality of instruction rows are false states, i.e., the row states of the other instruction rows are all false states, and the update code corresponding to the instruction row is modified to be empty, and only the code segment corresponding to the instruction row is retained, to determine the current code of the plurality of code rows.
[0197] In the embodiment of the present application, the implementation of each step can refer to the description of the corresponding step or operation of the above method embodiment, and the repeated content will not be described herein again.
[0198] In the embodiment of the present application, the implementation of each step can refer to the description of the corresponding step or operation of the above method embodiment, and the repeated content will not be described herein again.
[0199] In the embodiment of the present application, the implementation of each step can refer to the description of the corresponding step or operation of the above method embodiment, and the repeated content will not be described herein again.
[0200] The code pruning method provided by the embodiment determines whether the macro group type of a macro group is the first type. If yes, the original code of a plurality of code lines in an original code file is determined as current code of the plurality of code lines, the configuration file is parsed to obtain at least one macro identifier corresponding to the macro group and an enabling state corresponding to the macro identifier, at least one target macro is determined in the plurality of code lines according to the at least one macro identifier, and current line states of the plurality of code lines corresponding to the at least one target macro are determined according to the enabling state corresponding to the at least one macro identifier. If no, the configuration file is parsed to obtain a plurality of macro identifiers corresponding to the macro group and an enabling state corresponding to the macro identifier, a plurality of target macros are determined in the plurality of code lines according to the plurality of macro identifiers, instruction lines corresponding to the plurality of target macros and current line states corresponding to the instruction lines are determined in the plurality of code lines according to the enabling state corresponding to the plurality of macro identifiers, the original code corresponding to the plurality of instruction lines is modified according to the current line states corresponding to the plurality of instruction lines to obtain updated code corresponding to the plurality of code lines, a code segment corresponding to an instruction line and a line type corresponding to the instruction line are determined for any one instruction line, the current line state of the code segment is determined as a true state when the current line state of the instruction line is the true state, the updated code corresponding to the instruction line is modified according to the line type and the current line state of the instruction line to determine current code of a plurality of code lines corresponding to the instruction line, and the current line state of the code segment is determined as a false state when the current line state of the instruction line is the false state, and the updated code corresponding to the plurality of code lines is determined as current code corresponding to the plurality of code lines. In this way, the macro group state and type are managed by the configuration file, the pruning strategy is dynamically selected based on the macro group type and the configured enabling state, the syntax error or logic loss caused by simple macro removal is avoided, the correctness and reliability of the pruned code are ensured, and the code pruning efficiency is improved.
[0201] Figure 4 A structure diagram of a code pruning device provided by an embodiment of the present application is provided. Please refer to Figure 4 The code pruning device 400 includes an acquisition module 401, a determination module 402, an updating module 403, and a pruning module 404.
[0202] The acquisition module 401 is configured to acquire a configuration file and an original code file. The configuration file includes macro group identifiers of a plurality of macro groups in the original code file and an enabling state corresponding to at least one macro in each macro group.
[0203] The determination module 402 is configured to determine macro group types corresponding to the plurality of macro groups according to the configuration file.
[0204] The updating module 403 is configured to update the plurality of code lines corresponding to the macro group in the original code file according to the macro group type of the macro group and the configuration file, to obtain current codes and current line states of the plurality of code lines, respectively, and the updating process includes at least one of code analysis processing and code modification processing.
[0205] The pruning module 404 is configured to prune the plurality of current codes corresponding to the plurality of macro groups according to the plurality of current line states corresponding to the plurality of macro groups, to obtain a target code file.
[0206] Optionally, the updating module 403 is specifically configured to:
[0207] determine whether the macro group type of the macro group is a first type;
[0208] If yes, the original codes of the plurality of code lines in the original code file are determined as the current codes of the plurality of code lines, the code analysis processing is performed on the plurality of code lines corresponding to the macro group in the original code file according to the configuration file, and the current line states of the plurality of code lines are determined, respectively;
[0209] If no, the code analysis processing and the code modification processing are performed on the plurality of code lines corresponding to the macro group in the original code file according to the configuration file, to obtain the current codes and the current line states of the plurality of code lines, respectively.
[0210] Optionally, the updating module 403 is specifically configured to:
[0211] perform the parsing processing on the configuration file to obtain at least one macro identifier corresponding to the macro group and an enabling state corresponding to the macro identifier;
[0212] determine at least one target macro in the plurality of code lines according to the at least one macro identifier;
[0213] determine the current line states of the plurality of code lines corresponding to the at least one target macro, respectively, according to the enabling state corresponding to the at least one macro identifier.
[0214] Optionally, the updating module 403 is specifically configured to:
[0215] determine instruction lines corresponding to the at least one target macro in the plurality of code lines and current line states corresponding to the instruction lines according to the enabling state corresponding to the at least one macro identifier;
[0216] For any one instruction line, determine the code segment corresponding to the instruction line, when the current line state of the instruction line is a true state, determine the current line state corresponding to the code segment as a true state, and update the current line state of the instruction line as a false state, when the current line state of the instruction line is a false state, determine the current line state corresponding to the code segment as a false state.
[0217] Optionally, the module described above, the updating module 403 is specifically used for:
[0218] The configuration file is parsed to obtain at least one macro identifier corresponding to the macro group and an enabling state corresponding to the macro identifier.
[0219] According to the at least one macro identifier, at least one target macro is determined in the plurality of code lines.
[0220] According to the enabling state corresponding to the at least one macro identifier, the current line state of the plurality of code lines corresponding to the at least one target macro is determined respectively, and the original code corresponding to the at least one target macro is modified respectively to determine the current code corresponding to the plurality of code lines respectively.
[0221] Optionally, the module described above, the updating module 403 is specifically used for:
[0222] According to the enabling state corresponding to the at least one macro identifier, the instruction line corresponding to the plurality of target macros respectively in the plurality of code lines and the current line state corresponding to the instruction line are determined.
[0223] According to the current line state corresponding to the plurality of instruction lines, the original code corresponding to the plurality of instruction lines is modified to obtain the updating code corresponding to the plurality of code lines respectively.
[0224] For any one instruction line, determine the code segment corresponding to the instruction line, and determine the line type corresponding to the instruction line.
[0225] When the current line state of the instruction line is a true state, the current line state corresponding to the code segment is determined as a true state, and the updating code corresponding to the instruction line is modified according to the line type and the current line state of the instruction line to determine the current code of the plurality of code lines corresponding to the instruction line.
[0226] When the current line state of the instruction line is a false state, the current line state corresponding to the code segment is determined as a false state, and the updating code corresponding to the plurality of code lines is determined as the current code corresponding to the plurality of code lines.
[0227] Optionally, the module described above, the updating module 403 is specifically used for:
[0228] If the line type is the first line type, it is determined whether an adjacent previous instruction line in the instruction line is an instruction line with a second line type and a false current line state, and if so, the update code corresponding to the instruction line is modified according to the code corresponding to the second line type, and the current code of the plurality of code lines is determined, the current code including the code of the instruction line and the code corresponding to the code segment.
[0229] If the line type is the third line type, it is determined whether the line states corresponding to the instruction lines other than the instruction line in the plurality of instruction lines are false states, and if so, the update code corresponding to the instruction line is modified to be empty, and the current code of the plurality of code lines is determined, the current code including the code corresponding to the code segment.
[0230] Figure 5 A structural schematic diagram of an electronic device provided by an embodiment of the present application is provided. Referring to FIG. 5, Figure 5 The electronic device 500 can include a memory 501, a processor 502, and a transceiver 503.
[0231] The memory 501 is configured to store program instructions.
[0232] The processor 502 is configured to execute the program instructions stored in the memory, so that the electronic device 500 performs the above method.
[0233] The transceiver 503 can include a transmitter and / or a receiver. The transmitter can also be referred to as a sender, a transmitter, a transmission port or a transmission interface, and the like. The receiver can also be referred to as a receiver, a receiving port or a receiving interface, and the like. The memory 501, the processor 502 and the transceiver 503 are connected to each other through a bus 504.
[0234] The embodiment of the present application also provides a computer program product, which can be executed by a processor, and when the computer program product is executed, the above method can be implemented.
[0235] The code clipping device, the electronic device, the computer readable storage medium and the computer program product of the embodiment of the present application can execute the technical solutions shown in the above code clipping method embodiment, and the implementation principles and beneficial effects are similar, which will not be repeated here.
[0236] It should be noted that, for the foregoing method embodiments, for the sake of simple description, they are all described as a combination of a series of actions, but those skilled in the art should know that the present application is not limited to the order of the actions described, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.
[0237] Further, it should be noted that although each step in the flowchart 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 can include multiple sub-steps or multiple stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily sequential, but can be executed in rotation or alternation with other steps or sub-steps or stages of other steps.
[0238] It should be understood that the above-mentioned device embodiments are only schematic, and the device of the present application can also be implemented in other ways. For example, the division of units / modules in the above-mentioned embodiments is only a logical functional division, and actual implementation can have another division method. For example, multiple units, modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed.
[0239] In addition, unless otherwise specified, each functional unit / module in each embodiment of the present application can be integrated in one unit / module, or each unit / module can exist physically, or two or more units / modules can be integrated together. The integrated unit / module can be realized in the form of hardware or in the form of a software program module.
[0240] If the integrated units / modules are implemented in the form of hardware, the hardware can be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes, but is not limited to, transistors, memristors, etc. Unless otherwise specified, the processor can be any appropriate hardware processor, such as a CPU, a GPU, an FPGA, a DSP, an ASIC, etc. Unless otherwise specified, the storage unit can be any appropriate magnetic storage medium or magneto-optical storage medium, such as resistive random access memory (RRAM), dynamic random access memory (DRAM), static random access memory (SRAM), enhanced dynamic random access memory (EDRAM), high-bandwidth memory (HBM), hybrid memory cube (HMC), etc.
[0241] If the integrated units / modules are implemented in the form of software program modules and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the essential part or all or part of the technical solutions that make contributions to the prior art can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the embodiments of the present application. The aforementioned storage medium includes a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.
[0242] In the above embodiments, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above embodiments are described, but as long as the combination of the technical features does not exist contradictory, it should be considered as the scope of the present application
[0243] Other embodiments of the application will be apparent to those skilled in the art from consideration of the specification and practice of the application disclosed herein. It is intended that the specification and examples be considered as exemplary only, with the true scope and spirit of the application being indicated by the following claims.
[0244] It is to be understood that the application is not limited to the precise construction herein disclosed and shown in the drawings, and that various changes in shape, size and arrangements of parts can be made without departing from the scope of the application. The scope of the application is limited only by the claims that follow.
Claims
1. A method of tailoring of code, characterized by, The method comprises: obtaining a configuration file and an original code file, the configuration file comprising macro group identifiers of a plurality of macro groups in the original code file and an enabling state corresponding to at least one macro in each macro group; determining macro group types corresponding to the plurality of macro groups according to the configuration file; for any one macro group, performing update processing on a plurality of code lines corresponding to the macro group in the original code file according to the macro group type of the macro group and the configuration file, to obtain current codes and current line states corresponding to the plurality of code lines, the update processing comprising at least one of code analysis processing and code modification processing; performing pruning processing on a plurality of current codes corresponding to the plurality of macro groups according to a plurality of current line states corresponding to the plurality of macro groups, to obtain a target code file.
2. The method of claim 1, wherein, determining whether the macro group type of the macro group is a first type; if yes, determining original codes of a plurality of code lines in the original code file as current codes of the plurality of code lines, and performing code analysis processing on the plurality of code lines corresponding to the macro group in the original code file according to the configuration file, to determine current line states corresponding to the plurality of code lines; if no, performing code analysis processing and code modification processing on the plurality of code lines corresponding to the macro group in the original code file according to the configuration file, to obtain current codes and current line states corresponding to the plurality of code lines. performing code analysis processing on the plurality of code lines corresponding to the macro group in the original code file according to the configuration file, to determine current line states corresponding to the plurality of code lines, comprises:
3. The method of claim 2, wherein, performing parsing processing on the configuration file to obtain at least one macro identifier corresponding to the macro group and an enabling state corresponding to the macro identifier; determining at least one target macro in the plurality of code lines according to the at least one macro identifier; determining current line states of a plurality of code lines corresponding to the at least one target macro according to the enabling state corresponding to the at least one macro identifier. determining current line states of a plurality of code lines corresponding to the at least one target macro according to the enabling state corresponding to the at least one macro identifier, comprises:
4. The method of claim 3, wherein, determining instruction lines corresponding to the at least one target macro and current line states corresponding to the instruction lines in the plurality of code lines according to the enabling state corresponding to the at least one macro identifier; for any one instruction line, determining a code segment corresponding to the instruction line, determining a current line state of the code segment as a true state when a current line state of the instruction line is the true state, and updating the current line state of the instruction line to a false state, and determining the current line state of the code segment as the false state when the current line state of the instruction line is the false state. 5. The method according to any one of claims 2-4, characterized in that, Based on the configuration file, code analysis and modification are performed on multiple lines of code corresponding to the macro groups in the original code file to obtain the current code and current line status corresponding to the multiple lines of code, including: The configuration file is parsed to obtain multiple macro identifiers corresponding to the macro group and the enable states corresponding to the macro identifiers. Based on the multiple macro identifiers, multiple target macros are determined in the multiple lines of code; Based on the enable states corresponding to the multiple macro identifiers, the current line state of the multiple code lines corresponding to the multiple target macros is determined, and the original code corresponding to the multiple target macros is modified to determine the current code corresponding to the multiple code lines.
6. The method of claim 5, wherein, Based on the enable states corresponding to the multiple macro identifiers, the current line state of multiple lines of code corresponding to the multiple target macros is determined, and the original code corresponding to the multiple target macros is modified. Determining the current code corresponding to the multiple lines of code includes: Based on the enable states corresponding to the multiple macro identifiers, determine the instruction lines corresponding to the multiple target macros in the multiple code lines, and the current line state corresponding to the instruction lines; Based on the current line status of multiple instruction lines, the original code corresponding to each of the multiple instruction lines is modified to obtain the updated code corresponding to each of the multiple code lines. For any given instruction line, determine the code segment corresponding to the instruction line and the line type corresponding to the instruction line; When the current line state of the instruction line is true, the current line state corresponding to the code segment is determined to be true, and the update code corresponding to the instruction line is modified according to the line type and the current line state of the instruction line, and the current code of multiple code lines corresponding to the instruction line is determined; When the current line state of the instruction line is a false state, the current line state corresponding to the code segment is determined to be a false state, and the update code corresponding to the multiple code lines is determined to be the current code corresponding to the multiple code lines.
7. The method of claim 6, wherein, Based on the line type and the current line state of the instruction line, the update code corresponding to the instruction line is modified, and the current code of multiple code lines corresponding to the instruction line is determined, including: If the line type is the first line type, then determine whether the previous instruction line adjacent to the instruction line is an instruction line with the line type of the second line type and the current line state is false. If so, then modify the update code corresponding to the instruction line according to the code corresponding to the second line type, and determine the current code of the multiple code lines. The current code includes the code of the instruction line and the code corresponding to the code segment. If the line type is the third line type, then determine whether the line status corresponding to each instruction line other than the instruction line is a false state. If so, modify the update code corresponding to the instruction line to empty, and determine the current code of the multiple code lines. The current code includes the code corresponding to the code segment.
8. A code pruning apparatus characterized by comprising: The device includes: An acquisition module is configured to acquire a configuration file and an original code file, the configuration file including macro group identifiers of a plurality of macro groups in the original code file and an enabling state corresponding to at least one macro in each macro group; A determination module is configured to determine macro group types corresponding to the plurality of macro groups according to the configuration file; For any one macro group, an updating module is configured to perform updating processing on a plurality of code lines corresponding to the macro group in the original code file according to the macro group type of the macro group and the configuration file, to obtain current codes and current line states corresponding to the plurality of code lines respectively, the updating processing including at least one of code analysis processing and code modification processing; A clipping module is configured to perform clipping processing on a plurality of current codes corresponding to the plurality of macro groups according to a plurality of current line states corresponding to the plurality of macro groups, to obtain a target code file.
9. An electronic device, comprising: It comprises: a processor and a memory connected with the processor in communication; the memory stores computer execution instructions; the processor executes the computer execution instructions stored in the memory to implement the method of any one of claims 1 to 7.
10. A computer program product, characterised in that, It comprises a computer program which, when executed by a processor, implements the method of any one of claims 1 to 7.