CN116450490A - Conditional statement value determining method, device and storage medium - Google Patents

Conditional statement value determining method, device and storage medium Download PDF

Info

Publication number
CN116450490A
CN116450490A CN202210015744.5A CN202210015744A CN116450490A CN 116450490 A CN116450490 A CN 116450490A CN 202210015744 A CN202210015744 A CN 202210015744A CN 116450490 A CN116450490 A CN 116450490A
Authority
CN
China
Prior art keywords
statement
value
conditional
determining
block
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210015744.5A
Other languages
Chinese (zh)
Inventor
赵明
张锦
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Suzhou Dongchayun Information Technology Co ltd
Original Assignee
Suzhou Dongchayun Information Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Suzhou Dongchayun Information Technology Co ltd filed Critical Suzhou Dongchayun Information Technology Co ltd
Priority to CN202210015744.5A priority Critical patent/CN116450490A/en
Publication of CN116450490A publication Critical patent/CN116450490A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3644Software debugging by instrumenting at runtime
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3624Software debugging by performing operations on the source code, e.g. via a compiler
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3676Test management for coverage analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases

Abstract

The embodiment of the invention provides a conditional statement value determining method, a conditional statement value determining device and a storage medium, wherein the method comprises the following steps: determining at least one conditional statement in the source code; setting a stake-inserting statement before and/or after the conditional statement based on the conditional statement; and determining the value of the conditional statement corresponding to the instrumentation statement based on the execution condition of the instrumentation statement, wherein the value indicates the execution result of the conditional statement.

Description

Conditional statement value determining method, device and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and apparatus for determining a value of a conditional statement, and a storage medium.
Background
A judgment statement often contains a plurality of conditional statements, and the conditional coverage has stronger testing capability than the judgment coverage; the condition coverage can determine the value of each condition statement in one judgment statement, and the judgment coverage can only judge the whole result of the judgment statement, and ignores the value of each condition statement. In the prior art, the white box test technology can directly insert the source code to obtain the value of the judgment statement, but under the condition of inserting the byte code, the white box test tool analyzes the byte code, which can cause the source code information to be lost, so that the value of the conditional statement in the source code can not be obtained.
Disclosure of Invention
The embodiment of the invention provides a conditional statement value determining method, a conditional statement value determining device and a storage medium.
The technical scheme of the embodiment of the invention is realized as follows:
the embodiment of the invention provides a conditional statement value determining method, which comprises the following steps:
determining at least one conditional statement in the source code;
setting a stake-inserting statement before and/or after the conditional statement based on the conditional statement;
and determining the value of the conditional statement corresponding to the instrumentation statement based on the execution condition of the instrumentation statement, wherein the value indicates the execution result of the conditional statement.
In the above solution, the determining at least one conditional statement in the source code includes:
determining a judging statement block containing judging statements from statement blocks of the source codes; wherein the statement block includes: a plurality of consecutively distributed code statements; the code statement includes: an entry statement and an exit statement;
and determining the conditional statement in the judging statement according to the block information corresponding to the judging statement block.
In the above scheme, the block information includes: position information of the judgment statement block;
the determining at least one conditional statement in the judging statement according to the block information corresponding to the judging statement block comprises the following steps:
Determining a judgment statement in a judgment statement block from source codes according to the position information of the judgment statement block; wherein the decision statement comprises one or more conditional statements;
analyzing the judging sentences to determine the conditional sentences in the judging sentences.
In the above solution, setting the instrumentation statement before and/or after the conditional statement based on the conditional statement includes:
performing byte code analysis on the conditional statement through assembly language (ASM) to generate a test statement; the test statement is the same or opposite to the conditional statement logic;
setting a stake-inserting statement containing a first numerical value in front of a test statement based on the test statement;
and/or the number of the groups of groups,
setting a stake-inserting statement containing a second value after the test statement.
In the above solution, the determining, based on the execution status of the instrumentation statement, a value of a conditional statement corresponding to the instrumentation statement, where the value indicates an execution result of the conditional statement includes:
determining the value of the test statement based on the execution status of the instrumentation statement containing the first numerical value and the instrumentation statement containing the second numerical value;
Determining the value of the conditional statement according to the value of the test statement; wherein the value of the conditional statement indicates the execution result of the conditional statement.
In the above solution, the determining the value of the test statement based on the execution status of the instrumentation statement including the first value and the instrumentation statement including the second value includes:
if the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, determining that the value of the test statement is a true Boolean value;
and/or the number of the groups of groups,
if the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, determining that the value of the test statement is a false Boolean value.
In the above solution, the determining the value of the conditional statement according to the value of the test statement includes:
when the test statement is the same as the conditional statement in logic, the value of the conditional statement is equal to the value of the test statement;
and/or the number of the groups of groups,
and when the test statement is logically opposite to the conditional statement, the value of the conditional statement is equal to the value of the test statement after the inversion.
The embodiment of the invention also provides a conditional statement value determining device, which comprises: the device comprises a first determining module, a setting module and a second determining module;
the first determining module is used for determining at least one conditional statement in the source code;
the setting module is used for setting a stake-inserting statement before and/or after the conditional statement based on the conditional statement;
the second determining module is configured to determine, based on an execution condition of the instrumentation statement, a value of a conditional statement corresponding to the instrumentation statement, where the value indicates an execution result of the conditional statement.
In the above solution, the first determining module is specifically configured to:
determining a judging statement block containing judging statements from statement blocks of the source codes; wherein the statement block includes: a plurality of consecutively distributed code statements; the code statement includes: an entry statement and an exit statement;
and determining the conditional statement in the judging statement according to the block information corresponding to the judging statement block.
In the above scheme, the block information includes: position information of the judgment statement block;
the first determining module is specifically configured to: determining a judgment statement in a judgment statement block from source codes according to the position information of the judgment statement block; wherein the decision statement comprises one or more conditional statements;
Analyzing the judging sentences to determine the conditional sentences in the judging sentences.
In the above scheme, the setting module is specifically configured to:
performing byte code analysis on the conditional statement through assembly language (ASM) to generate a test statement; the test statement is the same or opposite to the conditional statement logic;
setting a stake-inserting statement containing a first numerical value in front of a test statement based on the test statement;
and/or the number of the groups of groups,
setting a stake-inserting statement containing a second value after the test statement.
In the above solution, the second determining module is specifically configured to:
determining the value of the test statement conditional statement based on the execution status of the instrumentation statement containing the first numerical value and the instrumentation statement containing the second numerical value;
determining the value of the conditional statement according to the value of the test statement; wherein the value of the conditional statement indicates the execution result of the conditional statement.
In the above solution, the second determining module is specifically configured to:
if the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, determining that the value of the test statement is a true Boolean value;
And/or the number of the groups of groups,
if the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, determining that the value of the test statement is a false Boolean value.
In the above solution, the second determining module is specifically configured to:
when the test statement is the same as the conditional statement in logic, the value of the conditional statement is equal to the value of the test statement;
and/or the number of the groups of groups,
and when the test statement is logically opposite to the conditional statement, the value of the conditional statement is equal to the value of the test statement after the inversion.
The embodiment of the invention also provides a conditional statement value determining device, which comprises: a processor and a memory for storing a computer program capable of running on the processor;
and the processor is used for executing any one of the steps of the conditional statement value determining method when the computer program is run.
The embodiment of the invention also provides a computer storage medium, which is characterized in that the computer storage medium stores computer executable instructions; the steps of the conditional statement value determining method can be realized after the computer executable instructions are executed by the processor.
In this embodiment, at least one conditional statement in the source code is determined, and based on the conditional statement, a instrumentation statement is set before and/or after the conditional statement, and the value of the conditional statement indicating the execution result of the conditional statement is determined according to the execution status of the instrumentation statement, so that the execution result of the conditional statement is determined based on the execution status of the instrumentation statement, the execution result of the conditional statement, that is, the value result, is obtained in the instrumentation process, and further statistics of the conditional coverage rate can be achieved based on the value of the conditional statement, thereby supplementing test cases, improving test efficiency, and enabling software test coverage rate information to be more comprehensive.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are required to be used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only embodiments of the present invention, and that other drawings can be obtained according to the provided drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic flow chart of a conditional statement value determining method provided by the invention;
FIG. 2 is a flowchart illustrating a method for determining a statement block in source code according to an embodiment of the invention;
FIG. 3 is a schematic diagram of a composition structure of statement block information in an embodiment of the invention;
FIG. 4 is a flow chart of a condition block generation in an embodiment of the present invention;
FIG. 5 is a schematic diagram of a composition structure of conditional block information according to an embodiment of the present invention;
FIG. 6 is a schematic structural diagram of a conditional statement value determining apparatus according to an embodiment of the present invention;
FIG. 7 is a schematic diagram of another conditional statement value determining apparatus according to an embodiment of the present invention;
fig. 8 (a) - (i) are example codes in an embodiment of the present invention.
Detailed Description
The present invention will be further described in detail with reference to the accompanying drawings, for the purpose of making the objects, technical solutions and advantages of the present invention more apparent, and the described embodiments should not be construed as limiting the present invention, and all other embodiments obtained by those skilled in the art without making any inventive effort are within the scope of the present invention.
Embodiments and features of embodiments in this application may be combined with each other arbitrarily without conflict. The steps illustrated in the flowchart of the figures may be performed in a computer system, such as a set of computer-executable instructions. Also, while a logical order is depicted in the flowchart, in some cases, the steps depicted or described may be performed in a different order than presented herein.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used herein is for the purpose of describing embodiments of the invention only and is not intended to be limiting of the invention.
Before further describing embodiments of the present invention in detail, terminology and terminology involved in communications in embodiments of the present invention will be described.
The embodiment of the invention provides a conditional statement value determination method. As shown in fig. 1, the method includes:
step S101: determining at least one conditional statement in the source code;
step S102: setting a stake-inserting statement before and/or after the conditional statement based on the conditional statement;
step S103: and determining the value of the conditional statement corresponding to the instrumentation statement based on the execution condition of the instrumentation statement, wherein the value indicates the execution result of the conditional statement.
Specifically, in step S101, the at least one conditional statement may be one statement in the program code. Illustratively, the conditional statement may be a conditional statement of the predicate statements contained in the source code; here, the conditional statement may be one or more than one conditional statement; the conditional statement is an operational expression containing relational operators, e.g., a= =0, c-! =1, or d > =1, etc., where the relational operator includes, but is not limited to: equal to, not equal to, less than, greater than or equal to, etc.
Further, in the step S101, the determining at least one conditional statement in the source code includes: from the statement blocks of the source code, a judgment statement block containing a judgment statement is determined.
The statement block includes: a plurality of consecutively distributed code statements; the code statement includes: an entry statement and an exit statement; and determining the conditional statement in the judging statement according to the block information corresponding to the judging statement block.
Both the entry statement and the exit statement herein are statements in the plurality of code statements in the statement block. If the entry statement is executed, at least one other statement in the statement block is executed until the entry statement is executed.
Illustratively, the statement block may be a code block for statement-directed loop logic execution.
Specifically, the block information is generated based on the determined statement blocks after static analysis is performed on the source code to determine the statement blocks;
the block information includes at least: the statement block ID, the file ID to which the statement block belongs, the type code of the statement block, the position information of the statement block and the code line number of the statement block entry statement; here, the type code of the statement block indicates the type of the statement block, and the statement block containing the judgment statement is determined as the judgment statement block.
In this embodiment, the type code of the statement block is a numerical value identified in 8-bit hexadecimal form, and if the number is less than 8 bits, 0 is used for filling in before the type code.
The position information of the statement block is used for determining the position of the statement block from the file to which the statement block belongs.
The code line number of the entry statement in the statement block is used to locate the position of the entry statement.
Specifically, static analysis is performed on the source code to generate a statement block.
The statement block comprises a plurality of code statements which are distributed continuously; each statement block comprises a code statement including an entry statement, namely a start statement, and an exit statement, namely an end statement; according to the code line number of the entry sentence in the current sentence block and the code line number of the entry sentence in the next sentence block adjacent to the current sentence block, all the code sentences included in the current sentence block can be determined from the source code.
The determination and generation process of statement blocks and block information corresponding to the statement blocks in source code are described in a specific embodiment:
for example, the source code may be as shown in fig. 8 (a):
the statement block determined by the static analysis of the source code is shown in fig. 2, and note that the comment statement in line 5 is not used as the statement block. C0, C1, C2, C3, C4, C5, C6 and C7 are used as the statement block ID of the generated statement block. And performing type coding on the statement blocks C0 to C7, and generating block information corresponding to the statement blocks.
As shown in fig. 3, fig. 3 is block information corresponding to a generation statement block in the present embodiment; the file ID to which the source code belongs is set to 1; illustrating: the entry statement of statement block C0 is located in the third line of the source code, so statement block C0 entry statement code line number is 3; the entry statement of statement block C4 is located in the tenth line of the source code, so statement block C4 entry statement code line number is 11.
In this embodiment, the determining, from the statement blocks of the source code, the determination statement block including the determination statement includes: and determining a judgment statement block containing a judgment statement according to the type code in the block information corresponding to the statement block.
Specifically, whether the statement block is a judgment statement block is determined according to whether a number at a first preset position in the type code corresponding to the statement block is 1.
In this embodiment, the first preset position is a second position from high to low; the type code is expressed by A, and the type codes A and 0x0F000000 are processed into an AND algorithm, namely A &0x0F000000; if the result of a &0x0F000000 is 0x01000000, the number at the first preset position in the type coding of the current sentence block is 1, and the current sentence block is a decision sentence block including a decision sentence.
If the result of a &0x0F000000 is not 0x01000000, it indicates that the current sentence block is not 1 at the first preset position in the type encoding of the current sentence block, and the current sentence block is not a decision sentence block including a decision sentence.
For example, the type code of the statement block C4 in the block information shown in fig. 3 is 1100000, which is only a hexadecimal value of 7 bits, and 0 is complemented before 1100000, so that the type code of the statement block C4 is complemented with a hexadecimal value of 0x0100000 of 8 bits; when 0x0100000 and 0x0F000000 are used as the and algorithm, and the result is 0x01000000, the statement block C4 is a determination statement block including a determination statement.
Further, the determining at least one conditional statement in the decision statement according to the block information corresponding to the decision statement block includes: determining a judgment statement in a judgment statement block from source codes according to the position information of the judgment statement block; wherein the decision statement comprises one or more conditional statements; analyzing the judging sentences to determine the conditional sentences in the judging sentences.
Specifically, analyzing the judgment statement to generate a condition block; and determining the conditional statement in the judging statement according to the conditional block information corresponding to the conditional block.
The conditional block information includes: a conditional block location index, determination statement block location information, the file ID of the determination statement, a conditional block code, and a conditional block type identifier; the condition block type identifier may be a number, a letter or a character string composed of the number and the letter, may be customized by a user, or may be a default value of the system, which is not specifically limited herein; the condition block includes: single conditional statement block, single piece combined statement block, and decision statement block.
The conditional block position index identifies the sequential encoding of conditional statements in the conditional block from left to right in the decision statement for determining the position of the conditional block in the decision statement; the statement block position information is used for determining the position of the statement block from the file to which the statement block belongs; the conditional block type identifies a type for representing the conditional block by different numbers, i.e., whether the conditional block is a single conditional statement block, a single combined statement block, or a decision statement block.
Specifically, for example, in the block information shown in fig. 3, the type code of the statement block C4 is used to determine that the statement block C4 is a determination statement block including a determination statement, and then the position of the statement block is determined from the file 1 to which the statement block C4 belongs based on the position information in the statement block C4, and the determination statement is determined And analyzing the judging statement to generate a condition block.
As shown in fig. 4; the generated conditional blocks are denoted by D0, D1, D2, D3, D4, D5 and D6; based on the generated conditional block, determining conditional block information corresponding to the conditional block, as shown in fig. 5; in this embodiment, the condition block type identifier uses a numerical representation in the form of a 4-bit integer, where 1109 indicates that the condition block is a single condition statement block, 1110 indicates that the condition block is a single piece combination statement block, and 1111 indicates that the condition block is a decision statement block. In this embodiment, in the condition blocks generated by the decision statement, D0, D1, D2, D4, and D5 are single-condition statement blocks, D3 is a single-piece combined statement block, and D6 is the decision statement block; and determining conditional statements corresponding to the conditional blocks D0, D1, D2, D4 and D5 according to the conditional block position information corresponding to the conditional blocks D0, D1, D2, D4 and D5, namely determining the conditional statements in the judging statements.
In step S103, the execution result of the conditional statement is represented by a boolean value; if the execution result is true, the value of the executed conditional statement is true; if the execution result is false, the value of the executed conditional statement is false.
It should be noted that, in this embodiment, by determining at least one conditional statement in the source code, setting a instrumentation statement before and/or after the conditional statement based on the conditional statement, and determining a value of the conditional statement indicating an execution result of the conditional statement through an execution condition of the instrumentation statement, so, determining an execution result of the conditional statement based on an execution condition of the instrumentation statement, a value of the conditional statement indicating an execution result of the conditional statement is obtained in an instrumentation process, and statistics of a conditional coverage rate can be achieved based on the value of the conditional statement, thereby supplementing a test case, improving test efficiency, and making software test coverage rate information more comprehensive.
Further, after determining the conditional statement in the decision statement, setting a instrumentation statement before and/or after the conditional statement based on the conditional statement, including: performing byte code analysis on the conditional statement through assembly language (ASM) to generate a test statement; the test statement is the same or opposite to the conditional statement logic; setting a stake-inserting statement containing a first numerical value in front of a test statement based on the test statement; and/or setting the instrumentation statement containing the second value after the test statement.
Specifically, the method further comprises: determining a logic operator corresponding to the conditional statement; based on the logical operator, performing byte code analysis on the conditional statement through assembly language (ASM) to generate a test statement; here, the test statement is a conditional statement for test.
Specifically, using adjacent logic operators after the conditional statement as the logic operators corresponding to the conditional statement; the logical operators include, but are not limited to: and operators (≡), or operators (||), non-operators (|), exclusive-or operators (≡), etc.
Specifically, determining the type of a judging node in the judging statement according to the type code in the block information corresponding to the judging statement; determining a logic operator corresponding to the last conditional statement in the judging statement based on the judging node type;
the decision node type includes at least one of: an if node type, a while node type, a for node type, and a do_while node type; determining the type of the judging node according to the value at a second preset position in the type code; here, the second preset position may be customized by a user, or a system default value may be used.
In this embodiment, if the value at the second preset position is 1, it indicates that the type of the determination node in the determination statement block is an if node type; if the value at the second preset position is 3, the judgment node type in the judgment statement block is a for node type; if the value at the second preset position is 4, the judgment node type in the judgment statement block is a while node type; if the value at the second preset position is 5, the judgment node type in the judgment statement block is a do-while node type;
if the judging node type is an if node type, the logical operator corresponding to the last conditional statement in the judging statement is AND; if the judging node type is not the if node type, the logical operator corresponding to the last conditional statement in the judging statement is OR.
Taking the block information shown in fig. 3 as an embodiment, the second preset position is the 3 rd bit from high to low; statement block C4 is a judgment statement block, and statement block C4 includes conditional statements corresponding to conditional block D0, conditional block D1, conditional block D2, conditional block D4, and conditional block D5; according to the judgment statement It can be seen that the operator corresponding to the conditional statement a= =0 corresponding to the condition D0 is "||", and the operator corresponding to the conditional statement "bbb". Equals (b) corresponding to the condition block D1 is "l|";&&"; the operator corresponding to the conditional statement c= 1 corresponding to the conditional block D2 is "||"; the operator corresponding to the conditional statement d= =2 corresponding to the conditional block D4 is "&&"; an operator corresponding to a conditional statement "eee" = e "corresponding to the conditional block D5 needs to be determined according to a determination node type in the determination statement; judging that the sentence block C4 is coded into 1100000 in a type and is only a hexadecimal numerical value of 7 bits, and supplementing 0 before 1100000, so that the type coding of the sentence block C4 is supplemented into hexadecimal numerical value 0x 0100000 of 8 bits; the second preset position is 1, which indicates that the node type in the decision statement block C4 is an if node, and the logical operator corresponding to the conditional statement in the conditional statement block D5 is "&&"operator".
After determining a logical operator corresponding to the conditional statement, performing byte code analysis on the conditional statement through assembly language (ASM) based on the logical operator to generate a test statement; in some embodiments, when the generated test statement is logically the same as an original conditional statement in the decision statement, that is, the test statement is the same as the conditional statement, the test statement is the conditional statement; in other embodiments, when the generated test statement is logically opposite to the original conditional statement in the decision statement, the test statement is a statement that is the inverse of the conditional statement; for example: the original conditional statement in the judgment statement is "a-! =0 ", which generates a test statement" a= =0 ", the generated test statement being logically opposite to the original conditional statement in the decision statement; another example is: the original conditional statement in the judging statement is 'i > 0', the generated test statement is 'i < =0', and the generated test statement is opposite to the original conditional statement in the judging statement in logic; and the following steps: the original conditional statement in the judging statement is 'i < =10', the generated test statement is 'i > 10', and the generated test statement is opposite to the original conditional statement in the judging statement in logic.
Further, the setting the instrumentation statement before and/or after the conditional statement based on the conditional statement includes: setting a stake-inserting statement containing a first numerical value in front of a test statement based on the test statement; and/or setting the instrumentation statement containing the second value after the test statement.
Specifically, the instrumentation statement sets different values according to its position relative to the test statement; the numerical value may be a user-defined numerical value or a default numerical value of the system, which is not particularly limited herein; after the instrumentation statement containing the first numerical value is executed, the first numerical value is output; and outputting the second numerical value after the pile inserting sentence containing the second numerical value is ready to be executed.
The instrumentation statement herein may be a code statement that is inserted into execution, and the instrumentation statement is a code statement that is inserted into the instrumentation point location of the source code.
Further, the determining, based on the execution status of the instrumentation statement, a value of a conditional statement corresponding to the instrumentation statement, where the value indicates an execution result of the conditional statement, includes: determining the value of the test statement based on the execution status of the instrumentation statement containing the first numerical value and the instrumentation statement containing the second numerical value; determining the value of the conditional statement according to the value of the test statement; wherein the value of the conditional statement indicates the execution result of the conditional statement.
Specifically, the execution status of the instrumentation statement includes: whether the instrumentation statement is executed and the number of times the instrumentation statement is executed;
specifically, determining whether the instrumentation statement containing the first value is executed according to whether the first value exists in the execution status of the instrumentation statement; and determining the number of times the instrumentation statement containing the first numerical value is executed according to the number of times the first numerical value appears in the execution condition.
Determining whether the instrumentation statement containing the second numerical value is executed according to whether the second numerical value exists in the execution condition of the instrumentation statement; and determining the number of times the instrumentation statement containing the second numerical value is executed according to the number of times the second numerical value appears in the execution condition.
The execution times of the instrumentation statement containing the first numerical value are the execution times of the test statement and the execution times of the conditional statement; determining whether a test statement corresponding to the instrumentation statement is executed or not and an execution result after the execution based on whether the instrumentation statement containing the first numerical value and the instrumentation statement containing the second numerical value are executed or not; and determining the execution result of the conditional statement according to the execution result of the test statement.
Further, the determining the value of the test statement based on the execution status of the instrumentation statement including the first value and the instrumentation statement including the second value includes: if the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, determining that the value of the test statement is a true Boolean value; and/or if the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, determining that the value of the test statement is a false boolean value.
Further, the determining the value of the conditional statement according to the value of the test statement includes: when the test statement is the same as the conditional statement in logic, the value of the conditional statement is equal to the value of the test statement; and/or when the test statement is logically opposite to the conditional statement, the value of the conditional statement is equal to the value of the test statement after the inversion.
Specifically, in an embodiment, if the test statement generated after the bytecode analysis of the conditional statement is the same as the conditional statement, if the instrumentation statement including the first value and the instrumentation statement including the second value are both executed, the value of the test statement is true, the value of the conditional statement is true, which indicates that the execution result of the conditional statement is true after the conditional statement is executed; the number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed;
If the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, the value of the test statement is false, the value of the conditional statement is false, and after the conditional statement is executed, the execution result of the conditional statement is false; the number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed.
For example: the source code is as shown in fig. 8 (b):
the conditional statement is a-! =0 and b-! =0; conditional statement a-! =0 denoted by a, conditional statement b-! =0 denoted B; the logical operator corresponding to the conditional statement A is "&"; after the ASM analyzes the byte codes of the conditional sentences, the generated test sentences are the same as the conditional sentences A and B in logic, namely the generated test sentences are the conditional sentences A and B; after setting the instrumentation statement before and/or after the conditional statement, the code is as shown in fig. 8 (c):
wherein, system.out.printIn (A1) and System.out.printIn (A2) are the stake-inserted sentences of the conditional sentence A;
After system.out.printin (A1) is executed, a first value is output; after system.out.printin (A2) is executed, a second value is output; the system.out.printin (B1) and the system.out.printin (B2) are the instrumentation statements system.out.printin (B1) of the conditional statement B, and then output the first value; after system.out.printin (B2) is executed, a second value is output.
If both the system.out.printin (A1) and the system.out.printin (A2) are executed, the value of the conditional statement a is true, which indicates that the execution result of the conditional statement a is true after the conditional statement a is executed;
if the system, out, prin (A1) is executed and the system, out, prin (A2) is not executed, the value of the conditional statement a is false, which indicates that the execution result of the conditional statement a is false after the conditional statement a is executed.
If both system.out.printin (B1) and system.out.printin (B2) are executed, the value of the conditional statement B is true, indicating that the execution result of the conditional statement B is true after the conditional statement B is executed;
if the system, out, printin (B1) is executed and the system, out, printin (B2) is not executed, the value of the conditional statement B is false, which indicates that the execution result of the conditional statement B is false after the conditional statement B is executed.
As another example, the source code is as shown in fig. 8 (d):
the conditional statement is i < = 10, i >0 and i >1; the conditional statement i < = 10 is denoted by M, the conditional statement i >0 is denoted by N, and the conditional statement i >1 is denoted by V; the logical operator corresponding to the conditional statement M is "& }, the logical operator corresponding to the conditional statement N is" & }, and the operator corresponding to the conditional statement V is "||" based on the fact that the judgment statement is of a while node type; after the ASM analyzes the byte codes of the conditional sentences, the generated test sentences are the same as the conditional sentences M, the conditional sentences N and the conditional sentences V in logic, namely the generated test sentences are the conditional sentences M, the conditional sentences N and the conditional sentences V; after setting the instrumentation statement before and/or after the conditional statement, the code is as shown in fig. 8 (e):
wherein, system.out.printIn (M1) and System.out.printIn (M2) are the stake-inserted sentences of the conditional sentence M;
after system.out.printin (M1) is executed, a first value is output; after system.out.printin (M2) is executed, a second value is output; system.out.printin (N1) and system.out.printin (N2) are the inserted sentences of conditional sentence N; after system.out.printin (N1) is executed, a first value is output; after system.out.printin (N2) is executed, a second value is output; system.out.printin (V1) and system.out.printin (V2) are the inserted sentences of conditional sentence V; after system.out.printin (V1) is executed, a first value is output; after system.out.printin (V2) is executed, a second value is output.
If both the system.out.printin (M1) and the system.out.printin (M2) are executed, the value of the conditional statement M is true, which indicates that the execution result of the conditional statement is true after the conditional statement is executed;
if the system, out, printin (M1) is executed and the system, out, printin (M2) is not executed, the value of the conditional statement M is false, which indicates that the execution result of the conditional statement M is false after the conditional statement M is executed.
If both system.out.printin (N1) and system.out.printin (N2) are executed, the value of the conditional statement N is true, which indicates that the execution result N of the conditional statement is true after the conditional statement N is executed;
if the system, out, prin (N1) is executed and the system, out, prin (N2) is not executed, the value of the conditional statement N is false, which indicates that the execution result of the conditional statement N is false after the conditional statement N is executed.
If both the system.out.printin (V1) and the system.out.printin (V2) are executed, the value of the conditional statement V is true, which indicates that the execution result of the conditional statement V is true after the conditional statement V is executed;
if the system, out, prin (V1) is executed and the system, out, prin (V2) is not executed, the value of the conditional statement V is false, which indicates that the execution result of the conditional statement V is false after the conditional statement V is executed.
In another embodiment, if the test statement generated after the bytecode analysis of the conditional statement is logically opposite to the conditional statement, if the instrumentation statement including the first value and the instrumentation statement including the second value are both executed, the value of the test statement is true, the value of the conditional statement is false, which indicates that the execution result of the conditional statement is false after the conditional statement is executed; the number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed;
if the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, the value of the test statement is false, the value of the conditional statement is true, and the execution result of the conditional statement is true after the conditional statement is executed; the number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed.
For example, the source code is as shown in fig. 8 (f):
the conditional statement is c-! =0 and d-! =0; conditional statement c-! =0 denoted by C, conditional statement d-! =0 denoted D; the logical operator corresponding to the conditional statement C is "||", and the operator corresponding to the conditional statement B is "&"; after the ASM analyzes the byte code of the conditional statement, the generated test statement is inverted and is opposite to the logic of the conditional statement A and the conditional statement B, namely the generated test statement is the result of inverting the conditional statement C and the conditional statement D; test statement C' is c= 0; test statement D' is d= 0; although the test statement is logically opposite to the original conditional statement, for logical equivalence to the original judgment statement, after setting the instrumentation statement before and/or after the test statement, the code is as in fig. 8 (g):
Wherein, system. Out. PrintIn (C1) and System. Out. PrintIn (C2) are the inserted sentences of the test sentence C';
after system.out.printin (C1) is executed, a first value is output; after system.out.printin (C2) is executed, a second value is output; system.out.printin (D1) and system.out.printin (D2) are the instrumentation statements of test statement D'; after system.out.printin (D1) is executed, a first value is output; after system.out.printin (D2) is executed, a second value is output.
If both system.out.printin (C1) and system.out.printin (C2) are executed, the value of the test statement C' is true, the value of the conditional statement C is false, which indicates that after the conditional statement C is executed, the execution result of the conditional statement C is false;
if the system. Out. Printin (C1) is executed and the system. Out. Printin (C2) is not executed, the value of the test statement C' is false, the value of the conditional statement C is true, which indicates that the execution result of the conditional statement C is true after the conditional statement C is executed.
If both system.out.printin (B1) and system.out.printin (B2) are executed, the value of the test statement D' is true, the value of the conditional statement D is false, which indicates that after the conditional statement D is executed, the execution result of the conditional statement D is false;
If the system. Out. Printin (D1) is executed and the system. Out. Printin (D2) is not executed, the value of the test statement D' is false, the value of the conditional statement D is true, which indicates that the execution result of the conditional statement D is true after the conditional statement D is executed.
As another example, the source code is as shown in fig. 8 (h):
the conditional statement is j < = 10, j >0 and j >1; the conditional statement j < = 10 is represented by E, the conditional statement j >0 is represented by F, and the conditional statement j >1 is represented by G; the logical operator corresponding to the conditional statement E is "||", the logical operator corresponding to the conditional statement F is "|", and the operator corresponding to the conditional statement G is "|", based on the judgment that the statement is of a while node type; after the ASM analyzes the byte code of the conditional statement, the generated test statement E is j < = 10 and has the same logic as the conditional statement E, the conditional statement F 'is j < = 0 and has opposite logic to the conditional statement F, and the conditional statement G' is j < = 1 and has opposite logic to the conditional statement G; although the test statement is logically opposite to the original conditional statement, in order to be logically equivalent to the original judgment statement, after the instrumentation statement is set before and/or after the test statement, the code is as shown in fig. 8 (i):
Wherein, system.out.printin (E1) and system.out.printin (E2) are the stake-inserted sentences of the conditional sentence E; after system.out.printin (E1) is executed, a first value is output; after system.out.printin (E2) is executed, a second value is output;
system.out.printin (F1) and system.out.printin (F2) are the instrumentation statements of test statement F'; after system.out.printin (F1) is executed, a first value is output; after system.out.printin (F2) is executed, a second value is output;
system.out.printin (G1) and system.out.printin (G2) are the instrumentation statements of test statement G'; after system.out.printin (G1) is executed, a first value is output; after system.out.printin (G2) is executed, a second value is output.
If both the system.out.printin (E1) and the system.out.printin (E2) are executed, the value of the conditional statement E is true, which indicates that the execution result of the conditional statement is true after the conditional statement is executed;
if the system, out, prin (E1) is executed and the system, out, prin (E2) is not executed, the value of the conditional statement E is false, which indicates that the execution result of the conditional statement E is false after the conditional statement E is executed.
If both system.out.printin (F1) and system.out.printin (F2) are executed, the value of the test statement F' is true, the value of the conditional statement F is false, indicating that the execution result F of the conditional statement is false after the conditional statement N is executed;
If the system. Out. Printin (F1) is executed and the system. Out. Printin (F2) is not executed, the value of the test statement F' is false, the value of the conditional statement F is true, indicating that the execution result of the conditional statement F is true after the conditional statement F is executed.
If both the system.out.printin (G1) and the system.out.printin (G2) are executed, the value of the test statement G' is true, the value of the conditional statement G is false, which indicates that the execution result of the conditional statement G is false after the conditional statement G is executed;
if the system out. Printin (G1) is executed and the system out. Printin (G2) is not executed, the value of the conditional statement G' is false, the value of the conditional statement G is true, which indicates that the execution result of the conditional statement G is true after the conditional statement G is executed.
The following describes a conditional statement value determining method according to an embodiment of the present invention with a specific example,
step 1: performing static analysis on the source code to determine at least one statement block;
wherein the statement block is a sequence of consecutively distributed code statements or expressions, the code statements comprising: an entry statement and an exit statement; it can only enter from its unique entry statement and can only transfer control at the end of the unique exit statement, if one of the statements is executed, then all of the statements can be executed.
Step 2: determining the block information of the statement block and storing the block information into a database;
the block information includes at least: the statement block ID, the file ID to which the statement block belongs, the type code of the statement block, the position information of the statement block and the code line number of the statement block entry statement; the statement block is type coded, which is represented by 8-bit hexadecimal digits.
Step 3: determining a judgment statement block according to the type code of the statement block;
specifically: determining whether the statement block is a judging statement block according to whether the number on the second bit from high to low of the type code corresponding to the statement block is 1; assuming that a type code is A, calculating 'A &0x0F 000000', and if the result is '0 x 01000000', indicating that the basic block contains a judgment statement; otherwise, the basic block does not contain a judgment statement, wherein the judgment statement comprises: decision statements of branch structure and loop structure.
Step 4: after determining a judging statement block, determining the node type of the judging statement block;
determining the type of the judging node in the judging statement block according to the number in the third position from high to low of the type code corresponding to the statement block; converting the type code into a number A with a 16 system number of 8; calculating A &0x00F00000, and if the result is '0 x 00100000', indicating that the node type of the judgment statement contained in the basic block is an if node; if the result is "0x00300000", the node type of the decision statement included in the basic block is for node;
If the result is "0x00400000", the node type of the judgment statement contained in the basic block is a while node; if the result is "0x00400000", the node type of the decision statement contained in the basic block is a do-while node.
Step 5: after determining a judging statement block, determining the judging statement in the judging statement block according to the file ID of the statement block in the block information corresponding to the judging statement block, the position information of the statement block and the code line number of the statement block entry statement.
Specifically, the file in which the judging statement block is located is determined according to the file ID to which the statement block belongs, the position of the judging statement block in the file is determined according to the position information of the statement block, and the judging statement in the judging statement block is determined according to the code line number of the statement block entry statement and to the specific code line of the judging statement block in the file.
Step 6: analyzing the judging statement to generate a condition block; and determining the conditional statement in the judging statement according to the conditional block information corresponding to the conditional block.
Specifically, the condition block includes: a single conditional statement block, a single piece combination statement block, and a judgment statement block; the conditional block information includes: a conditional block location index, determination statement block location information, the file ID of the determination statement, a conditional block code, and a conditional block type identifier;
Wherein the conditional block position index identifier is the sequential encoding of conditional sentences in the conditional blocks from left to right in the decision sentences, and is used for determining the position of the conditional blocks in the decision sentences;
the statement block position information is used for determining the position of the statement block from the file to which the statement block belongs;
the condition block code refers to a single condition, a single piece combination and a program code corresponding to the judgment statement contained in the judgment statement.
The conditional block type identifies a type for representing the conditional block by different numbers, i.e., whether the conditional block is a single conditional statement block, a single combined statement block, or a decision statement block.
Step 7: determining judgment statement information in a condition block and all single condition statement information contained in the judgment statement according to the condition block type identifier in the condition block information;
specifically, the conditional block type identification is represented using a numerical value in the form of a 4-bit integer, assuming that the determination of the conditional block type is: when the condition block type identifier is 1109, the condition block is represented as a single condition statement block; when the condition block type is 1110, the condition block is a single piece combined statement block; when the condition block type flag is 1111, it indicates that the condition block is a decision statement block.
Extracting condition block information corresponding to all condition blocks with the condition block type of 1109, and generating a corresponding json file; and the conditional block position indexes corresponding to all the single condition sentences are consistent with the sequential codes of the single condition sentences in the json file.
Step 8: determining a logic operator corresponding to the conditional statement;
intercepting a logic operator behind each single condition statement contained in the judging statement; determining a logic operator corresponding to the last conditional statement in the judging statement based on the judging node type;
if the node type of the judging statement is an if node type, the logical operator corresponding to the last conditional statement is "&";
if the node type of the judging statement is other node types except the if node type, the logical operator corresponding to the last conditional statement is "||"; and storing the logical operators corresponding to the conditional sentences.
Step 9: and traversing the cache to obtain all functions corresponding to the currently loaded class file.
Step 10: and accessing all the functions, comparing the accessed code line number with the code line number of the entry statement of the statement block in the source code, marking the code line number if the type of the statement block corresponding to the code line number is a judgment statement block, and acquiring the condition block information corresponding to the judgment statement block and the logic operator corresponding to the condition statement from a cache.
Step 11: performing byte code analysis on the condition block information corresponding to the judgment statement blocks marked by the code line numbers and the logic operators corresponding to the condition blocks through ASM to generate test statements;
the test statement may be the same as or opposite to the original conditional statement logic; and program codes formed by the test statement and the logical operators corresponding to the test statement are logically equivalent to the judgment statement operation contained in the judgment statement block.
Step 12: setting a instrumentation statement containing a first value before the test statement, and setting an instrumentation statement containing a second value after the test statement.
Step 13: determining the value of the conditional statement based on the execution status of the instrumentation statement containing the first numerical value and the instrumentation statement containing the second numerical value;
the value of the conditional statement is divided into three types, wherein the conditional statement is executed but the value is true or false, the conditional statement takes a true value and the conditional statement takes a false value.
If the test statement generated after the byte code analysis of the conditional statement is the same as the conditional statement logic, if the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, the value of the conditional statement is true, and the execution result of the conditional statement is true after the execution of the conditional statement is indicated; the number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed; if the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, the value of the conditional statement is false, and after the conditional statement is executed, the execution result of the conditional statement is false;
The number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed.
If the test statement generated after the byte code analysis of the conditional statement is opposite to the conditional statement in logic, if the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, the value of the test statement is true, the value of the conditional statement is false, and the execution result of the conditional statement is false after the execution of the conditional statement is indicated; the number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed; the number of false values taken by the conditional statement is equal to the number of times the instrumentation statement containing the first value is executed.
If the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, the value of the test statement is false, the value of the conditional statement is true, and the execution result of the conditional statement is true after the conditional statement is executed; the number of times the conditional statement is executed is equal to the number of times the instrumentation statement containing the first value is executed; the number of times the conditional statement takes the true value is equal to the number of times the instrumentation statement containing the first value is executed.
As shown in fig. 6, fig. 6 is a schematic structural diagram of a conditional statement value determining apparatus according to an embodiment of the present invention, including: a first determination module 601, a setting module 602, and a second determination module 603;
the first determining module 601 is configured to determine at least one conditional statement in the source code;
the setting module 602 is configured to set, based on the conditional statement, a instrumentation statement before and/or after the conditional statement;
the second determining module 603 is configured to determine, based on an execution status of the instrumentation statement, a value of a conditional statement corresponding to the instrumentation statement, where the value indicates an execution result of the conditional statement.
Specifically, the first determining module 601 is specifically configured to determine a decision statement block including a decision statement from statement blocks of source code; wherein the statement block includes: a plurality of consecutively distributed code statements; the code statement includes: an entry statement and an exit statement; and determining the conditional statement in the judging statement according to the block information corresponding to the judging statement block.
Specifically, the block information includes: position information of the judgment statement block; the first determining module 601 is specifically configured to determine, according to location information of a decision statement block, a decision statement in the decision statement block from a source code; wherein the decision statement comprises one or more conditional statements; analyzing the judging sentences to determine the conditional sentences in the judging sentences.
Specifically, the setting module 602 is specifically configured to perform byte code analysis on the conditional statement through assembly language (ASM) to generate a test statement; the test statement is the same or opposite to the conditional statement logic; setting a stake-inserting statement containing a first numerical value in front of a test statement based on the test statement; and/or setting the instrumentation statement containing the second value after the test statement.
Specifically, the second determining module 603 is specifically configured to determine a value of the test statement conditional statement based on an execution status of the instrumentation statement including the first value and the instrumentation statement including the second value; determining the value of the conditional statement according to the value of the test statement; wherein the value of the conditional statement indicates the execution result of the conditional statement.
Specifically, the second determining module 603 is specifically configured to determine that the value of the test statement is a boolean value if the instrumentation statement including the first value and the instrumentation statement including the second value are both executed; and/or if the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, determining that the value of the test statement is a false boolean value.
Specifically, the second determining module 603 is specifically configured to, when the test statement is logically the same as the conditional statement, make the value of the conditional statement equal to the value of the test statement; and/or when the test statement is logically opposite to the conditional statement, the value of the conditional statement is equal to the value of the test statement after the inversion.
To implement the method of the embodiment of the present invention, the embodiment of the present invention provides still another conditional statement value determining apparatus, specifically, as shown in fig. 7, the apparatus 70 includes a processor 701 and a memory 702 for storing a computer program capable of running on the processor;
wherein the processor 701 is configured to execute, when executing the computer program: determining at least one conditional statement in the source code; setting a stake-inserting statement before and/or after the conditional statement based on the conditional statement; and determining the value of the conditional statement corresponding to the instrumentation statement based on the execution condition of the instrumentation statement, wherein the value indicates the execution result of the conditional statement.
In an embodiment, the processor 701 is further configured to execute, when the computer program is executed: determining a judging statement block containing judging statements from statement blocks of the source codes; wherein the statement block includes: a plurality of consecutively distributed code statements; the code statement includes: an entry statement and an exit statement; and determining the conditional statement in the judging statement according to the block information corresponding to the judging statement block.
In an embodiment, the processor 701 is further configured to execute, when the computer program is executed: the block information includes: position information of the judgment statement block; determining a judgment statement in a judgment statement block from source codes according to the position information of the judgment statement block; wherein the decision statement comprises one or more conditional statements; analyzing the judging sentences to determine the conditional sentences in the judging sentences.
In an embodiment, the processor 701 is further configured to execute, when the computer program is executed: performing byte code analysis on the conditional statement through assembly language (ASM) to generate a test statement; the test statement is the same or opposite to the conditional statement logic; setting a stake-inserting statement containing a first numerical value in front of a test statement based on the test statement; and/or setting the instrumentation statement containing the second value after the test statement.
In an embodiment, the processor 701 is further configured to execute, when the computer program is executed: determining the value of the test statement conditional statement based on the execution status of the instrumentation statement containing the first numerical value and the instrumentation statement containing the second numerical value; determining the value of the conditional statement according to the value of the test statement; wherein the value of the conditional statement indicates the execution result of the conditional statement.
In an embodiment, the processor 701 is further configured to execute, when the computer program is executed: if the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, determining that the value of the test statement is a true Boolean value; and/or if the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, determining that the value of the test statement is a false boolean value.
In an embodiment, the processor 701 is further configured to execute, when the computer program is executed: when the test statement is the same as the conditional statement in logic, the value of the conditional statement is equal to the value of the test statement; and/or when the test statement is logically opposite to the conditional statement, the value of the conditional statement is equal to the value of the test statement after the inversion.
It should be noted that: the conditional statement value determining device and the conditional statement value determining method provided in the foregoing embodiments belong to the same concept, and specific implementation processes thereof are detailed in the method embodiments and are not described herein.
Of course, in practical application, as shown in fig. 7, the apparatus 70 may further include: at least one network interface 703. The various components in the conditional statement value determining apparatus 70 are coupled together by a bus system 704. It is appreciated that bus system 704 is used to enable connected communications between these components. The bus system 704 includes a power bus, a control bus, and a status signal bus in addition to the data bus. But for clarity of illustration, the various buses are labeled as bus system 704 in fig. 7. The number of the processors 701 may be at least one. The network interface 703 is used for wired or wireless communication between the conditional statement value determining apparatus 70 and other devices.
The memory 702 in the embodiment of the present invention is used to store various types of data to support the operation of the conditional statement value determining apparatus 70.
The method disclosed in the above embodiment of the present invention may be applied to the processor 701 or implemented by the processor 701. The processor 701 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware in the processor 701 or by instructions in the form of software. The processor 7901 may be a general purpose processor, a digital signal processor (DSP, digital Signal Processor), or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. The processor 701 may implement or perform the methods, steps, and logic blocks disclosed in embodiments of the present invention. The general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the method disclosed in the embodiment of the invention can be directly embodied in the hardware of the decoding processor or can be implemented by combining hardware and software modules in the decoding processor. The software modules may be located in a storage medium in a memory 702. The processor 701 reads information in the memory 702 and, in combination with its hardware, performs the steps of the method as described above.
In an exemplary embodiment, the conditional statement valuing determining means 70 may be implemented by one or more application specific integrated circuits (ASIC, application Specific Integrated Circuit), DSP, programmable logic device (PLD, programmable Logic Device), complex programmable logic device (CPLD, complex Programmable Logic Device), field programmable gate array (FPGA, field-Programmable Gate Array), general purpose processor, controller, microcontroller (MCU, micro Controller Unit), microprocessor (Microprocessor), or other electronic element for performing the foregoing methods.
In an exemplary embodiment, the present invention also provides a computer-readable storage medium, such as a memory 702 including a computer program executable by the processor 701 of the conditional statement value determining apparatus 70 to perform the steps of the method described above.
In particular, the embodiments of the present invention also provide a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, performs: determining at least one conditional statement in the source code; setting a stake-inserting statement before and/or after the conditional statement based on the conditional statement; and determining the value of the conditional statement corresponding to the instrumentation statement based on the execution condition of the instrumentation statement, wherein the value indicates the execution result of the conditional statement.
In one embodiment, the computer program, when executed by a processor, performs: determining a judging statement block containing judging statements from statement blocks of the source codes; wherein the statement block includes: a plurality of consecutively distributed code statements; the code statement includes: an entry statement and an exit statement; and determining the conditional statement in the judging statement according to the block information corresponding to the judging statement block.
In one embodiment, the computer program, when executed by a processor, performs: the block information includes: position information of the judgment statement block; determining a judgment statement in a judgment statement block from source codes according to the position information of the judgment statement block; wherein the decision statement comprises one or more conditional statements; analyzing the judging sentences to determine the conditional sentences in the judging sentences.
In one embodiment, the computer program, when executed by a processor, performs: performing byte code analysis on the conditional statement through assembly language (ASM) to generate a test statement; the test statement is the same or opposite to the conditional statement logic; setting a stake-inserting statement containing a first numerical value in front of a test statement based on the test statement; and/or setting the instrumentation statement containing the second value after the test statement.
In one embodiment, the computer program, when executed by a processor, performs: determining the value of the test statement conditional statement based on the execution status of the instrumentation statement containing the first numerical value and the instrumentation statement containing the second numerical value; determining the value of the conditional statement according to the value of the test statement; wherein the value of the conditional statement indicates the execution result of the conditional statement.
In one embodiment, the computer program, when executed by a processor, performs: if the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, determining that the value of the test statement is a true Boolean value; and/or if the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, determining that the value of the test statement is a false boolean value.
In one embodiment, the computer program, when executed by a processor, performs: when the test statement is the same as the conditional statement in logic, the value of the conditional statement is equal to the value of the test statement; and/or when the test statement is logically opposite to the conditional statement, the value of the conditional statement is equal to the value of the test statement after the inversion.
It should be noted that: the computer readable storage medium provided by the embodiment of the invention can be FRAM, ROM, PROM, EPROM, EEPROM, flash Memory, magnetic surface Memory, optical disk, CD-ROM or other Memory; but may be a variety of devices including one or any combination of the above memories.
The foregoing is merely exemplary embodiments of the present invention and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and scope of the present invention are included in the protection scope of the present invention.

Claims (16)

1. A method for determining a value of a conditional statement, the method comprising:
determining at least one conditional statement in the source code;
setting a stake-inserting statement before and/or after the conditional statement based on the conditional statement;
and determining the value of the conditional statement corresponding to the instrumentation statement based on the execution condition of the instrumentation statement, wherein the value indicates the execution result of the conditional statement.
2. The conditional statement value determining method of claim 1, wherein the determining at least one conditional statement in the source code comprises:
determining a judging statement block containing judging statements from statement blocks of the source codes; wherein the statement block includes: a plurality of consecutively distributed code statements; the code statement includes: an entry statement and an exit statement;
And determining the conditional statement in the judging statement according to the block information corresponding to the judging statement block.
3. The conditional statement value determining method according to claim 2, wherein the block information includes: position information of the judgment statement block;
the determining at least one conditional statement in the judging statement according to the block information corresponding to the judging statement block comprises the following steps:
determining a judgment statement in a judgment statement block from source codes according to the position information of the judgment statement block; wherein the decision statement comprises one or more conditional statements;
analyzing the judging sentences to determine the conditional sentences in the judging sentences.
4. The conditional statement value determining method according to claim 1, wherein the setting of the instrumentation statement before and/or after the conditional statement based on the conditional statement comprises:
performing byte code analysis on the conditional statement through assembly language (ASM) to generate a test statement; the test statement is the same or opposite to the conditional statement logic;
setting a stake-inserting statement containing a first numerical value in front of a test statement based on the test statement;
And/or the number of the groups of groups,
setting a stake-inserting statement containing a second value after the test statement.
5. The method for determining a value of a conditional statement according to claim 4, wherein determining a value of a conditional statement corresponding to the instrumentation statement based on an execution status of the instrumentation statement, the value indicating an execution result of the conditional statement, comprises:
determining the value of the test statement based on the execution status of the instrumentation statement containing the first numerical value and the instrumentation statement containing the second numerical value;
determining the value of the conditional statement according to the value of the test statement; wherein the value of the conditional statement indicates the execution result of the conditional statement.
6. The method for determining the value of a conditional statement according to claim 5, wherein determining the value of the test statement based on the execution status of the instrumentation statement including the first value and the instrumentation statement including the second value comprises:
if the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, determining that the value of the test statement is a true Boolean value;
and/or the number of the groups of groups,
if the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, determining that the value of the test statement is a false Boolean value.
7. The method for determining the value of a conditional statement according to claim 5 or 6, wherein the determining the value of the conditional statement according to the value of the test statement comprises:
when the test statement is the same as the conditional statement in logic, the value of the conditional statement is equal to the value of the test statement;
and/or the number of the groups of groups,
and when the test statement is logically opposite to the conditional statement, the value of the conditional statement is equal to the value of the test statement after the inversion.
8. A conditional statement value determining apparatus, the apparatus comprising: the device comprises a first determining module, a setting module and a second determining module;
the first determining module is used for determining at least one conditional statement in the source code;
the setting module is used for setting a stake-inserting statement before and/or after the conditional statement based on the conditional statement;
the second determining module is configured to determine, based on an execution condition of the instrumentation statement, a value of a conditional statement corresponding to the instrumentation statement, where the value indicates an execution result of the conditional statement.
9. The conditional statement value determining apparatus of claim 8, wherein the first determining module is specifically configured to:
Determining a judging statement block containing judging statements from statement blocks of the source codes; wherein the statement block includes: a plurality of consecutively distributed code statements; the code statement includes: an entry statement and an exit statement;
and determining the conditional statement in the judging statement according to the block information corresponding to the judging statement block.
10. The conditional statement value determining apparatus according to claim 9, wherein the block information includes: position information of the judgment statement block;
the first determining module is specifically configured to: determining a judgment statement in a judgment statement block from source codes according to the position information of the judgment statement block; wherein the decision statement comprises one or more conditional statements;
analyzing the judging sentences to determine the conditional sentences in the judging sentences.
11. The conditional statement value determining apparatus of claim 8, wherein the setting module is specifically configured to:
performing byte code analysis on the conditional statement through assembly language (ASM) to generate a test statement; the test statement is the same or opposite to the conditional statement logic;
setting a stake-inserting statement containing a first numerical value in front of a test statement based on the test statement;
And/or the number of the groups of groups,
setting a stake-inserting statement containing a second value after the test statement.
12. The conditional statement value determining apparatus of claim 11, wherein the second determining module is specifically configured to:
determining the value of the test statement conditional statement based on the execution status of the instrumentation statement containing the first numerical value and the instrumentation statement containing the second numerical value;
determining the value of the conditional statement according to the value of the test statement; wherein the value of the conditional statement indicates the execution result of the conditional statement.
13. The conditional statement value determining apparatus of claim 12, wherein the second determining module is specifically configured to:
if the instrumentation statement containing the first value and the instrumentation statement containing the second value are executed, determining that the value of the test statement is a true Boolean value;
and/or the number of the groups of groups,
if the instrumentation statement containing the first value is executed and the instrumentation statement containing the second value is not executed, determining that the value of the test statement is a false Boolean value.
14. The conditional statement value determining apparatus of claim 11 or 12, wherein the second determining module is specifically configured to:
When the test statement is the same as the conditional statement in logic, the value of the conditional statement is equal to the value of the test statement;
and/or the number of the groups of groups,
and when the test statement is logically opposite to the conditional statement, the value of the conditional statement is equal to the value of the test statement after the inversion.
15. A conditional statement value determining apparatus, the apparatus comprising: a processor and a memory for storing a computer program capable of running on the processor;
wherein the processor is adapted to perform the steps of the method of any of claims 1 to 7 when the computer program is run.
16. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 7.
CN202210015744.5A 2022-01-07 2022-01-07 Conditional statement value determining method, device and storage medium Pending CN116450490A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210015744.5A CN116450490A (en) 2022-01-07 2022-01-07 Conditional statement value determining method, device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210015744.5A CN116450490A (en) 2022-01-07 2022-01-07 Conditional statement value determining method, device and storage medium

Publications (1)

Publication Number Publication Date
CN116450490A true CN116450490A (en) 2023-07-18

Family

ID=87124285

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210015744.5A Pending CN116450490A (en) 2022-01-07 2022-01-07 Conditional statement value determining method, device and storage medium

Country Status (1)

Country Link
CN (1) CN116450490A (en)

Similar Documents

Publication Publication Date Title
CN108256164B (en) Boolean logic in a state machine lattice
CN110597814B (en) Structured data serialization and deserialization method and device
AU2014315619B2 (en) Methods and systems of four-valued simulation
CN111249736B (en) Code processing method and device
CN112231068B (en) Custom logic method, system and readable medium using domain specific language
CN111131403A (en) Message coding and decoding method and device for Internet of things equipment
CN106649217A (en) Data matching method and device
CN111209341B (en) Data storage method, device, equipment and medium of block chain
CN111651137B (en) Ordering method, ordering device, electronic device and computer equipment
CN110096264A (en) A kind of code operation method and device
CN111159278B (en) Data display method and device, electronic equipment and computer readable storage medium
CN109828759B (en) Code compiling method, device, computer device and storage medium
CN112486490B (en) Front-end code packaging method and device, electronic equipment and storage medium
CN116450490A (en) Conditional statement value determining method, device and storage medium
CN113742332A (en) Data storage method, device, equipment and storage medium
US9455742B2 (en) Compression ratio for a compression engine
CN109831544A (en) A kind of coding and storing method and system applied to E-mail address
CN109840080B (en) Character attribute comparison method and device, storage medium and electronic equipment
CN110505051B (en) Character string hash processing method and device
CN114025024A (en) Data transmission method and device
US9934035B2 (en) Device and method for tracing updated predicate values
CN115185524A (en) Vector instruction identification method and device, electronic equipment and computer-readable storage medium
CN113031952A (en) Method and device for determining execution code of deep learning model and storage medium
US20170117918A1 (en) Method and Apparatus for Calculating Estimated Data Compression Ratio
CN115951936B (en) Chip adaptation method, device, equipment and medium of vectorization compiler

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination