CN110286912B - Code detection method and device and electronic equipment - Google Patents

Code detection method and device and electronic equipment Download PDF

Info

Publication number
CN110286912B
CN110286912B CN201910597267.6A CN201910597267A CN110286912B CN 110286912 B CN110286912 B CN 110286912B CN 201910597267 A CN201910597267 A CN 201910597267A CN 110286912 B CN110286912 B CN 110286912B
Authority
CN
China
Prior art keywords
code
detected
error
level
error code
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.)
Active
Application number
CN201910597267.6A
Other languages
Chinese (zh)
Other versions
CN110286912A (en
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.)
Guangdong 3vjia Information Technology Co Ltd
Original Assignee
Guangdong 3vjia 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 Guangdong 3vjia Information Technology Co Ltd filed Critical Guangdong 3vjia Information Technology Co Ltd
Priority to CN201910597267.6A priority Critical patent/CN110286912B/en
Publication of CN110286912A publication Critical patent/CN110286912A/en
Application granted granted Critical
Publication of CN110286912B publication Critical patent/CN110286912B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • 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
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Software Systems (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention provides a code detection method, a code detection device and electronic equipment, and relates to the technical field of computers. The method comprises the following steps: compiling the code to be detected by using a preset compiling tool according to the pre-divided error code level; if the code to be detected is compiled successfully, generating a grammar tree; each element of the code to be detected exists in the grammar tree in the form of a node; traversing all nodes of the grammar tree to detect whether any node has any level in error code levels, and obtaining a detection result. The invention realizes the comprehensive detection of the errors of each level of the code to be detected, and can meet the detection requirements of special codes such AS AS3 and the like.

Description

Code detection method and device and electronic equipment
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a code detection method, a code detection device, and an electronic device.
Background
In addition to mainstream code such as c++ in computer programming, there are some more specific codes in which many writing methods not supported in other mainstream languages can be compiled. The actionscript3.0 code language is typical of this type of special code, and will be described below by taking actionscript3.0 (AS 3) code AS an example. ActionScript is developed for Flash products by Macromedia (which is purchased by Adobe), is initially a simple script language, is now the latest version of ActionScript3.0, has grammar similar to JavaScript, has weaker constraint on writing, and thus causes non-uniform writing of each programmer, and greatly reduces the readability, expansibility and maintainability of codes. Because Adobe will stop the maintenance of Flash, the AS3 code must be either converted or rewritten to other languages in the future. Therefore, it is currently necessary to perform code detection on the AS3 to ensure that the existing AS3 code conforms to the writing habit and characteristics of the mainstream programming language, so that no grammar errors exist after the AS3 code is converted or rewritten into the mainstream programming language. The currently released code detection tool is mainly used for detecting codes based on factors such AS code complexity, code repetition proportion, annotation proportion and the like, and cannot meet the detection requirements of special codes such AS AS3 and the like.
Disclosure of Invention
The embodiment of the invention aims to provide a code detection method, a code detection device and electronic equipment, and the method realizes the comprehensive detection of errors of various levels of codes to be detected, and can meet the detection requirements of special codes such AS AS3 and the like.
In a first aspect, an embodiment of the present invention provides a code detection method, including: compiling the code to be detected by using a preset compiling tool according to the pre-divided error code level; if the code to be detected is compiled successfully, generating a grammar tree; each element of the code to be detected exists in the grammar tree in the form of a node; traversing all the nodes of the grammar tree to detect whether any one of the error code levels exists in any node, and obtaining a detection result.
With reference to the first aspect, the embodiment of the present invention provides a first possible implementation manner of the first aspect, where the method further includes: converting the code to be detected with error codes into a target programming language through overwriting; dividing the error code level according to the compiling result and the running result of the rewritten code to be detected and the code writing specification of the target programming language; the target programming language includes a C language or a c++ language.
With reference to the first possible implementation manner of the first aspect, the embodiment of the present invention provides a second possible implementation manner of the first aspect, wherein the error code level includes: the first-level error code is an error code which can cause the compiling failure of the rewritten code to be detected when the first-level error code exists in the rewritten code to be detected; the second-level error code is an error code which can lead the rewritten code to be detected to be successfully compiled but inevitably fails to run when the second-level error code exists in the rewritten code to be detected; the third-level error code is an error code which can lead the rewritten code to be detected to be successfully compiled but has running failure probability when the third-level error code exists in the rewritten code to be detected; the fourth-level error code is an error code which can lead the rewritten code to be detected to be successfully compiled and run successfully but the running result is an error or null value when the fourth-level error code exists in the rewritten code to be detected; and the fifth-level error code is an error code which does not influence the compiling and running of the rewritten code to be detected but does not accord with the code compiling specification of the target programming language when the fifth-level error code exists in the rewritten code to be detected.
With reference to the second possible implementation manner of the first aspect, the embodiment of the present invention provides a third possible implementation manner of the first aspect, wherein the step of traversing all the nodes of the syntax tree to detect whether any of the error code levels exists in the nodes, and obtaining a detection result includes: repeatedly executing a preset detection step until all the nodes in the grammar tree are detected; the detection step comprises the following steps: and selecting any node in the grammar tree as a first node, and detecting whether the first node and other nodes connected with the first node have any level of error codes recorded in the error code level or not to obtain a detection result.
With reference to the third possible implementation manner of the first aspect, an embodiment of the present invention provides a fourth possible implementation manner of the first aspect, where the method further includes: if the detection result comprises a node with the second-level error code, the third-level error code or the fourth-level error code, writing the detection result into an error report log, if the detection result comprises a node with the fifth-level error code, writing the detection result into a prompt log, and outputting the error report log and/or the prompt log written with the detection result.
With reference to the second possible implementation manner of the first aspect, an embodiment of the present invention provides a fifth possible implementation manner of the first aspect, where the method further includes: if the code to be detected fails to compile, determining that the first-stage error code exists in the code to be detected, writing code information causing the code to be detected to compile failure into an error report log, and outputting the error report log written with the code information causing the code to be detected to compile failure.
With reference to the first aspect or any one of the first to fifth possible implementation manners of the first aspect, the embodiment of the present invention provides a sixth possible implementation manner of the first aspect, wherein the code to be detected is actionscript3.0 code, and the preset compiling tool is flex-falcon.
In a second aspect, an embodiment of the present invention further provides a code detection apparatus, including: the code compiling module is used for compiling the code to be detected by utilizing a preset compiling tool according to the pre-divided error code level; the grammar tree module is used for generating a grammar tree when the code to be detected is compiled successfully; each element of the code to be detected exists in the grammar tree in the form of a node; and the detection module is used for traversing all the nodes of the grammar tree so as to detect whether any one of the error code levels exists in any node to obtain a detection result.
In a third aspect, an embodiment of the present invention provides an electronic device, including a memory, and a processor, where the memory stores a computer program executable on the processor, where the processor implements the steps of the method according to the first aspect when the processor executes the computer program.
In a fourth aspect, embodiments of the present invention provide a computer readable medium storing computer executable instructions that, when invoked and executed by a processor, cause the processor to implement the method of the first aspect.
The embodiment of the invention provides a code detection method, a code detection device and electronic equipment, wherein a code to be detected is compiled by a preset compiling tool according to the level of a pre-divided error code; secondly, if the code to be detected is compiled successfully, a grammar tree is generated (each element of the code to be detected exists in the grammar tree in the form of a node); and finally traversing all nodes of the grammar tree to detect whether any one of the error code levels exists in any node, and obtaining a detection result. According to the method, the grammar tree is compiled and generated for the code to be detected, all nodes in the grammar tree can be detected based on the error code level detection nodes by traversing all nodes in the grammar tree, the comprehensive detection of errors of all levels of the code to be detected is realized, and the detection requirements of special codes such AS AS3 and the like can be met.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention will be realized and attained by the structure particularly pointed out in the written description and drawings.
In order to make the above objects, features and advantages of the present invention more comprehensible, preferred embodiments accompanied with figures are described in detail below.
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 needed in the description of the embodiments or the prior art will be briefly described, and it is obvious that the drawings in the description below are some embodiments of the present invention, and other drawings can be obtained according to the drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flowchart of a code detection method according to an embodiment of the present invention;
FIG. 2 is a code detection flow chart provided in an embodiment of the present invention;
fig. 3 is a schematic structural diagram of a code detection device according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions of the present invention will be clearly and completely described in connection with the embodiments, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Considering the currently released code detection tool, the code is detected mainly based on factors such AS code complexity, code repetition proportion, annotation proportion and the like, and the detection requirement of special codes such AS AS3 and the like cannot be met.
Based on the above, the embodiment of the invention provides a code detection method, a device and an electronic device, and the method can detect nodes with all error code levels in a grammar tree by traversing all nodes in the grammar tree and detecting the nodes based on the error code levels, so that the comprehensive detection of errors of all levels of codes to be detected is realized, and the detection requirements of special codes such AS AS3 and the like can be met.
For the sake of understanding the present embodiment, a detailed description will be given of a code detection method disclosed in the embodiment of the present invention.
Embodiment one:
referring to a code detection method flowchart shown in fig. 1, the method provided by the embodiment of the invention can be applied to the detection of actionscript3.0 codes, and comprises the following steps:
s102: and compiling the code to be detected by using a preset compiling tool according to the pre-divided error code level.
Dividing the levels of the error codes in advance according to the influence of the error codes on the code compiling operation result, adding the levels of the error codes as the grading logic of the error codes into a preset compiling tool according to the divided levels of the error codes (the grading logic can be added into the compiling tool in a code mode), so that the compiling tool can carry out level identification on the error codes according to the levels of the error codes, and compiling the codes to be detected by using the preset compiling tool.
S104: if the code to be detected is compiled successfully, generating a grammar tree; the elements of the code to be detected are present in the syntax tree in the form of nodes.
If the code to be detected is successfully compiled by utilizing a compiling tool, a corresponding grammar tree is generated, and each element of the code exists in the form of a node. Various types of nodes exist in the compiling tool in the form of classes, and each element of the codes becomes a relatively independent object, and the detailed information of the nodes is stored in the object. The detailed information of each node includes: node id, node value, node type, node definition, parent node object, child node object, file full path where the node is located, and line number where the node is located. Therefore, from the information of a certain node, the detailed information of all the nodes before, after and after can be calculated.
S106: traversing all nodes of the grammar tree to detect whether any one of the error code levels exists in any node, and obtaining a detection result.
After the grammar tree is generated, because the error code level is used as the hierarchical logic of the error code and is added into a preset compiling tool, the compiling tool can analyze the grammar and the structure of the code by traversing the nodes so as to detect whether any level of the error code level exists in the nodes, namely, analyze whether the code corresponding to each node has errors or not and identify the error code level corresponding to the error code, thereby obtaining a detection result, wherein the detection result comprises all the codes with errors and the error code level.
The embodiment of the invention provides a code detection method, which compiles codes to be detected to generate a grammar tree, and can detect nodes with all error code levels in the grammar tree by traversing all nodes in the grammar tree and detecting the nodes based on the error code levels, thereby realizing the comprehensive detection of errors of all levels of the codes to be detected and meeting the detection requirements of special codes such AS AS3 and the like.
Considering that the writing specifications or habits of each code are different, if some unusual programming languages (to-be-detected codes) are to be converted or rewritten into target programming languages (common programming languages), and the writing specifications or habits of the common programming languages are to be met, then codes which are not supported by the common programming languages in the unusual programming languages need to be detected before conversion or rewriting, so that error codes are detected before code conversion, and the specific implementation of dividing the error code levels is provided in this embodiment regarding how to divide the error code levels:
converting the code to be detected with error code into target programming language; dividing error code levels according to the compiling result and the running result of the rewritten code to be detected and the code writing specification of the target programming language; the target programming language includes a C language or a c++ language. When dividing the level of the error code, firstly, the code to be detected with the error code is rewritten and converted into a target programming language, wherein the target programming language is a common programming language or a main stream programming language, and the error code level is divided according to the compiling operation result of the rewritten code to be detected (namely, the code to be detected is rewritten and converted into the target programming language) and the code writing specification of the target programming language. For example, the target programming language may be C language or c++ language, where the strictness of C language or c++ language is highest in the mainstream programming language, so that the code to be detected can be ensured to be easily transcribed into various languages based on the coding specification of C language or c++ language.
To further highlight the distinction between each level of error codes, the present embodiment provides details of the level of error codes, as shown in the following first level error code to fifth level error code:
the first-level error code is an error code which can cause the compiling failure of the rewritten code to be detected when the first-level error code exists in the rewritten code to be detected. The first level error code is the error code which causes the greatest risk of the code, and is the characteristic which cannot be supported in the main stream language, and cannot be compiled according to the original code or after the converted code is rewritten. For example, the first level error code may be: the class name initials without class name or type flags added are not uppercase; a renamed member is arranged between the parents and the children; one case in the switch has a plurality of break sentences; top-level functions, etc.
The second-level error code is an error code which can lead the rewritten code to be detected to be compiled successfully but run inevitably to fail when the second-level error code exists in the rewritten code to be detected. The second level error code is that code compilation can pass successfully when this level of error exists in the code, but after execution must result in crashes or stuck, i.e., execution must fail. For example, the second level error code may be: XML is not written according to the mainstream writing method during initialization; the function of the non-void return value does not write return; no type decision is made, a direct strong transition to another type is made, and a member of that type is called, etc.
And the third-level error code is an error code which can lead the rewritten code to be detected to be successfully compiled but has the running failure probability when the third-level error code exists in the rewritten code to be detected. The third level error code is that when the level error exists in the code, the code compiling can pass successfully, but after the code is run, the code can be crashed or blocked, namely, a certain running failure probability exists. For example, the third level error code may be: declaring the key of Dictionary as a dynamic type; the concat function is directly called without judging the empty of the group.
And the fourth-level error code is an error code which can lead the rewritten code to be detected to be successfully compiled and run successfully, but the running result is an error or null value when the fourth-level error code exists in the rewritten code to be detected. The fourth level error code is that when the level error exists in the code, the code compiling can pass successfully, the running cannot crash, namely the running is successful, but the error value and even the time blank value can be obtained. For example, the fourth level error code may be: strongly converting the dynamic type into Vector; the Dictionary type is used as a dynamic type; calling other attributes using match (); a certain value of Array is strongly converted to other types using as, etc.
The fifth-level error code is an error code which does not affect the compiling and running of the rewritten code to be detected, but does not conform to the code compiling specification of the target programming language when the fifth-level error code exists in the rewritten code to be detected. The fifth level error code is an error code which can successfully pass through compiling and running when the level error exists in the code and obtain a correct running result, but does not meet the code writing specification of the target programming language, the code writing is not standard enough, and the readability is poor, and the fifth level error code comprises two cases, wherein one case is named by using keywords of the main stream language, for example: typeDef, asm, explicit, goto, register, etc.; alternatively, the mainstream speech coding specification is not met, for example: the naming of the variables/functions is not in accordance with hump principle; constant naming does not use the principles of uppercase underlining; no empty judgment is carried out; the boundary crossing is not judged; no exception handling is added; too few notes or no format pairs; nested function writing is not standard, etc.
In order to more comprehensively detect errors in codes, the embodiment provides a specific implementation manner of traversing all nodes of a grammar tree to detect whether any level of error code levels exists in any node, so as to obtain a detection result:
repeatedly executing a preset detection step until all nodes in the grammar tree are detected; the detection step comprises the following steps: and selecting any node in the grammar tree as a first node, and detecting whether the first node and other nodes connected with the first node have any level of error codes recorded in the error code level or not to obtain a detection result. In performing the detection step, logic of whether the code is at risk (i.e., hierarchical logic of error code levels) is written in some type of node detection logic. For example: if non-override rename members cannot exist between the parent and child classes, searching parent class nodes and child class nodes through class nodes at the place where class nodes are analyzed, analyzing whether non-override rename members exist in the searched nodes, and adding error reporting or prompting logs according to error level division. In the above compiling tool generating the syntax tree, each node in the syntax tree is traversed according to the hierarchical logic of the error code level to execute the detecting step, and any node in the syntax tree is selected as the first node, because the detailed information of each node includes: the method comprises the steps of node id, node value, node type, node definition, father node object, son node object, file full path where the node is located and line number where the node is located, so that detailed information of all nodes connected with a first node can be calculated by acquiring the detailed information of the first node, and whether the first node has any level of error code recorded in the error level code or not is detected according to the first node and elements in other nodes connected with the first node, so that a detection result is obtained.
In order to more intuitively embody the detection result, the embodiment further provides a specific implementation manner of outputting the detection result:
if the detection result comprises a node with a second-level error code, a third-level error code or a fourth-level error code, writing the detection result into an error report log, and if the detection result comprises a node with a fifth-level error code, writing the detection result into a prompt log, and outputting the error report log and/or the prompt log written with the detection result. If the detection result includes a node with a second-level error code, a third-level error code or a fourth-level error code, that is, if the error code exists in the code to be detected, the error code is the second-level error code, the third-level error code or the fourth-level error code, and because the second-level error code, the third-level error code and the fourth-level error code can influence the running result of the code, when the second-level error code, the third-level error code or the fourth-level error code occurs, the code is reported to an error report log, the detection result is code information causing the running failure or the running result error of the code to be detected, and the error report log written with the detection result is output, so that a user can modify the error in the code to be detected according to the error code recorded in the error report log. If the detection result includes a node with a fifth-level error code, namely the error code exists in the code to be detected, the error code is the fifth-level error code, and because the fifth-level error code does not affect the running result of the code, when the fifth-level error code exists, the detection result is written into a prompt log, and the non-standard writing method existing in the code is displayed to a user in the form of the prompt log, so that the user can modify the non-standard writing method existing in the code to be detected according to the code with the non-standard writing method recorded in the prompt log.
Considering that the code to be detected may have a compile failure, the embodiment provides a specific implementation manner after the code to be detected has a compile failure:
if the code to be detected fails to be compiled, determining that a first-level error code exists in the code to be detected, writing code information which causes the code to be detected to be compiled into an error log, and outputting the error log written with the code information which causes the code to be detected to be compiled to be failed. If the compiling tool is used for compiling the code to be detected under the condition that the compiling is failed, the error code in the code to be detected is a first-stage error code, code information which causes the compiling failure of the code to be detected is written into an error report log, and the error report log which is written with the code information which causes the compiling failure of the code to be detected is output, so that a user can modify the error code in the code to be detected according to the code information which causes the compiling failure of the code to be detected and is recorded in the error report log.
Considering that the code detection method is applied in practice, the code to be detected is actionscript3.0 code, and the preset compiling tool is flex-falcon. Flex is an efficient, free open source framework that can be used to build expressive Web applications that can be implemented across browsers, desktops, and operating systems using Adobe Flash Player and Adobe AIR. The Flex-falcon is a new compiler for Flex, and in this embodiment, the Flex-falcon may be used as a pre-compilation tool. Because Adobe will stop the maintenance of Flash, actionscript3.0 (AS 3 for short) code will be either converted or rewritten to other languages in the future. Therefore, before these tasks start, it is necessary to ensure that the AS3 code complies with the writing habit and characteristics of the mainstream language, so the above code detection method can be used for detecting actionscript3.0 code to detect the characteristics of the AS3 that are not supported by the mainstream programming language, and does not comply with the coding habit and specification of the mainstream programming language.
In practical application, as a possible implementation manner, as shown in a code detection flow chart in fig. 2, when code detection is started, firstly, initializing a program of a compiling tool, compiling a code to be detected by using the compiling tool, if the compiling is failed (i.e. the compiling is failed), reporting an error, if the compiling is failed, taking an error code existing in the code to be detected as a first-level error code, and writing code information causing the compiling failure of the code to be detected into an error log (i.e. an error log in the figure). Generating a grammar tree if compiling passes (namely compiling is successful), adding the divided error codes into a compiling tool in a grading manner (namely adding rules in a graph), analyzing the grammar tree by traversing nodes in the grammar tree to detect whether any level of error code levels exists in the nodes, judging whether fifth-level code errors exist in the code to be detected or not when the nodes are detected, namely judging whether a prompt of code non-normative exists or not, if the detection result comprises the nodes with the fifth-level error codes, namely the code to be detected has the writing norms which do not accord with a target programming language, displaying the non-normative writing method existing in the code to a user in the form of prompt logs, judging whether analysis of all the nodes of the grammar tree is completed or not, if yes, ending the detection process, and judging whether second-level error codes, third-level error codes or fourth-level error codes exist in the code to be detected or not; if the prompt of code non-standardization does not exist, whether the second-level error code, the third-level error code or the fourth-level error code exists in the code to be detected is judged, and because the second-level error code, the third-level error code and the fourth-level error code can influence the running result of the code, when the second-level error code, the third-level error code or the fourth-level error code is determined to occur, error reporting is carried out on the error code, the detection result is written into an error report log (also can be called as an error log), and the code detection process is ended.
The embodiment of the invention provides a code detection method, which is used for preparing strict grading logic by dividing error codes and comprehensively detecting code grammar, hidden code hazards and the like by traversing nodes and grammar analysis. The code detection method provided by the embodiment generates the error report log and the prompt log, intuitively displays errors in the codes to the user, and provides convenience for the user to modify the error codes.
Embodiment two:
the embodiment of the invention provides a code detection device, referring to a schematic structural diagram of the code detection device shown in fig. 3, the device comprises:
the code compiling module 31 is configured to compile the code to be detected by using a preset compiling tool according to the pre-divided error code levels.
A syntax tree module 32, configured to generate a syntax tree when compiling the code to be detected is successful; the elements of the code to be detected are present in the syntax tree in the form of nodes.
The detecting module 33 is configured to traverse all nodes of the syntax tree to detect whether any level of error code levels exists in any node, so as to obtain a detection result.
In one embodiment, the apparatus further comprises:
the level dividing module is used for converting the code to be detected with the error code into a target programming language through rewriting; dividing error code levels according to the compiling result and the running result of the rewritten code to be detected and the code writing specification of the target programming language; the target programming language includes a C language or a c++ language.
In one embodiment, the error code levels divided by the level division module are:
the first-level error code is an error code which can cause the compiling failure of the rewritten code to be detected when the first-level error code exists in the rewritten code to be detected.
The second-level error code is an error code which can lead the rewritten code to be detected to be compiled successfully but run inevitably to fail when the second-level error code exists in the rewritten code to be detected.
And the third-level error code is an error code which can lead the rewritten code to be detected to be successfully compiled but has the running failure probability when the third-level error code exists in the rewritten code to be detected.
And the fourth-level error code is an error code which can lead the rewritten code to be detected to be successfully compiled and run successfully, but the running result is an error or null value when the fourth-level error code exists in the rewritten code to be detected.
The fifth-level error code is an error code which does not affect the compiling and running of the rewritten code to be detected, but does not conform to the code compiling specification of the target programming language when the fifth-level error code exists in the rewritten code to be detected.
In one embodiment, the detecting module 33 is further configured to repeatedly perform the preset detecting step until all nodes in the syntax tree are detected; the detection step comprises the following steps: and selecting any node in the grammar tree as a first node, and detecting whether the first node and other nodes connected with the first node have any level of error codes recorded in the error code level or not to obtain a detection result.
In one embodiment, the apparatus further comprises:
the log output module is used for writing the detection result into the error report log when the detection result contains the node with the second-level error code, the third-level error code or the fourth-level error code, writing the detection result into the prompt log when the detection result contains the node with the fifth-level error code, and outputting the error report log and/or the prompt log written with the detection result.
And the compiling failure module is used for determining that a first-stage error code exists in the code to be detected when the code to be detected fails to be compiled, writing code information which causes the code to be detected to be compiled into an error log, and outputting the error log written with the code information which causes the code to be detected to be compiled to be failed.
In one embodiment, the code to be detected mentioned in the above device is actionscript3.0 code, and the preset compiling tool is flex-falcon.
The embodiment of the invention provides a code detection device which has the same technical characteristics as the code detection method provided in the first embodiment, so that the same technical problems can be solved, and the same technical effects can be achieved.
The device provided in this embodiment has the same implementation principle and technical effects as those of the foregoing embodiment, and for brevity, reference may be made to the corresponding content in the foregoing method embodiment for a part of the description of the device embodiment that is not mentioned.
Embodiment III:
an electronic device according to an embodiment of the present invention, as shown in a schematic structural diagram of an electronic device in fig. 4, includes a processor 41 and a memory 42, where a computer program capable of running on the processor is stored in the memory, and the steps of the method provided in the first embodiment are implemented when the processor executes the computer program.
Referring to fig. 4, the electronic device further includes: bus 44 and communication interface 43, processor 41, communication interface 43 and memory 42 are connected by bus 44. The processor 41 is arranged to execute executable modules, such as computer programs, stored in the memory 42.
The memory 42 may include a high-speed random access memory (RAM, random Access Memory), and may further include a non-volatile memory (non-volatile memory), such as at least one magnetic disk memory. The communication connection between the system network element and the at least one other network element is achieved via at least one communication interface 43 (which may be wired or wireless), which may use the internet, a wide area network, a local network, a metropolitan area network, etc.
Bus 44 may be an ISA (Industry Standard Architecture ) bus, a PCI (Peripheral Component Interconnect, peripheral component interconnect standard) bus, or EISA (Extended Industry Standard Architecture ) bus, among others. The buses may be classified as address buses, data buses, control buses, etc. For ease of illustration, only one bi-directional arrow is shown in FIG. 4, but not only one bus or type of bus.
The memory 42 is configured to store a program, and the processor 41 executes the program after receiving an execution instruction, and the method executed by the apparatus for flow defining disclosed in any of the foregoing embodiments of the present invention may be applied to the processor 41 or implemented by the processor 41.
The processor 41 may be an integrated circuit chip with signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware in the processor 41 or by instructions in the form of software. The processor 41 may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), and the like. But may also be a digital signal processor (Digital Signal Processing, DSP for short), application specific integrated circuit (Application Specific Integrated Circuit, ASIC for short), off-the-shelf programmable gate array (Field-Programmable Gate Array, FPGA for short), or other programmable logic device, discrete gate or transistor logic device, discrete hardware components. The disclosed methods, steps, and logic blocks in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present invention may be embodied directly in the execution of a hardware decoding processor, or in the execution of a combination of hardware and software modules in a decoding processor. The software modules may be located in a random access memory, flash memory, read only memory, programmable read only memory, or electrically erasable programmable memory, registers, etc. as well known in the art. The storage medium is located in a memory 42 and the processor 41 reads information in the memory 42 and in combination with its hardware performs the steps of the method described above.
Embodiment four:
the embodiment of the invention provides a computer readable medium, wherein the computer readable medium stores computer executable instructions, and the computer executable instructions when called and executed by a processor cause the processor to implement the method described in the embodiment one.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present invention, and not for limiting the same; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some or all of the technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit of the invention.

Claims (9)

1. A code detection method, comprising:
compiling the code to be detected by using a preset compiling tool according to the pre-divided error code level;
if the code to be detected is compiled successfully, generating a grammar tree; each element of the code to be detected exists in the grammar tree in the form of a node;
traversing all the nodes of the grammar tree to detect whether any one of the error code levels exists in any node to obtain a detection result;
the step of traversing all the nodes of the grammar tree to detect whether any one of the error code levels exists in any node, and obtaining a detection result, including:
repeatedly executing a preset detection step until all the nodes in the grammar tree are detected; the detection step comprises the following steps: and selecting any node in the grammar tree as a first node, and detecting whether the first node and other nodes connected with the first node have any level of error codes recorded in the error code level or not to obtain a detection result.
2. The method according to claim 1, wherein the method further comprises:
converting the code to be detected with error codes into a target programming language through overwriting;
dividing the error code level according to the compiling result and the running result of the rewritten code to be detected and the code writing specification of the target programming language; the target programming language includes a C language or a c++ language.
3. The method of claim 2, wherein the error code level comprises:
the first-level error code is an error code which can cause the compiling failure of the rewritten code to be detected when the first-level error code exists in the rewritten code to be detected;
the second-level error code is an error code which can lead the rewritten code to be detected to be successfully compiled but inevitably fails to run when the second-level error code exists in the rewritten code to be detected;
the third-level error code is an error code which can lead the rewritten code to be detected to be successfully compiled but has running failure probability when the third-level error code exists in the rewritten code to be detected;
the fourth-level error code is an error code which can lead the rewritten code to be detected to be successfully compiled and run successfully but the running result is an error or null value when the fourth-level error code exists in the rewritten code to be detected;
and the fifth-level error code is an error code which does not influence the compiling and running of the rewritten code to be detected but does not accord with the code compiling specification of the target programming language when the fifth-level error code exists in the rewritten code to be detected.
4. A method according to claim 3, characterized in that the method further comprises:
if the detection result comprises a node with the second-level error code, the third-level error code or the fourth-level error code, writing the detection result into an error report log, if the detection result comprises a node with the fifth-level error code, writing the detection result into a prompt log, and outputting the error report log and/or the prompt log written with the detection result.
5. A method according to claim 3, characterized in that the method further comprises:
if the code to be detected fails to compile, determining that the first-stage error code exists in the code to be detected, writing code information causing the code to be detected to compile failure into an error report log, and outputting the error report log written with the code information causing the code to be detected to compile failure.
6. The method according to any one of claims 1 to 5, wherein the code to be detected is actionscript3.0 code, and the predetermined compiling tool is flex-falcon.
7. A code detection apparatus, comprising:
the code compiling module is used for compiling the code to be detected by utilizing a preset compiling tool according to the pre-divided error code level;
the grammar tree module is used for generating a grammar tree when the code to be detected is compiled successfully; each element of the code to be detected exists in the grammar tree in the form of a node;
the detection module is used for traversing all the nodes of the grammar tree to detect whether any one of the error code levels exists in the nodes or not, so as to obtain a detection result;
the detection module is further configured to: repeatedly executing a preset detection step until all the nodes in the grammar tree are detected; the detection step comprises the following steps: and selecting any node in the grammar tree as a first node, and detecting whether the first node and other nodes connected with the first node have any level of error codes recorded in the error code level or not to obtain a detection result.
8. An electronic device comprising a memory, a processor, the memory having stored therein a computer program executable on the processor, characterized in that the processor, when executing the computer program, implements the steps of the method of any of the preceding claims 1 to 6.
9. A computer readable medium having stored thereon computer executable instructions which, when invoked and executed by a processor, cause the processor to implement the method of any one of claims 1 to 6.
CN201910597267.6A 2019-07-03 2019-07-03 Code detection method and device and electronic equipment Active CN110286912B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910597267.6A CN110286912B (en) 2019-07-03 2019-07-03 Code detection method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910597267.6A CN110286912B (en) 2019-07-03 2019-07-03 Code detection method and device and electronic equipment

Publications (2)

Publication Number Publication Date
CN110286912A CN110286912A (en) 2019-09-27
CN110286912B true CN110286912B (en) 2023-08-18

Family

ID=68020528

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910597267.6A Active CN110286912B (en) 2019-07-03 2019-07-03 Code detection method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN110286912B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112035710A (en) * 2020-07-28 2020-12-04 长沙市到家悠享网络科技有限公司 Code detection method, device, equipment and storage medium
CN113031940B (en) * 2021-04-29 2024-08-09 武汉夜莺科技有限公司 Front-end framework development method and device and terminal equipment
CN117909218B (en) * 2023-12-12 2024-08-20 青矩技术股份有限公司 Script detection method, script detection device, script detection equipment and computer-readable storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100211939A1 (en) * 2009-02-18 2010-08-19 International Business Machines Corporation Processing an object-oriented query to retrieve data from a data source
CN107015813A (en) * 2017-04-19 2017-08-04 网易(杭州)网络有限公司 Method, device and electronic equipment that code is repaired
CN107463375A (en) * 2017-07-18 2017-12-12 上海斐讯数据通信技术有限公司 A kind of method and system for detecting source code
CN107506304A (en) * 2017-08-24 2017-12-22 方智林 Code detection method, device, electronic equipment and storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100211939A1 (en) * 2009-02-18 2010-08-19 International Business Machines Corporation Processing an object-oriented query to retrieve data from a data source
CN107015813A (en) * 2017-04-19 2017-08-04 网易(杭州)网络有限公司 Method, device and electronic equipment that code is repaired
CN107463375A (en) * 2017-07-18 2017-12-12 上海斐讯数据通信技术有限公司 A kind of method and system for detecting source code
CN107506304A (en) * 2017-08-24 2017-12-22 方智林 Code detection method, device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN110286912A (en) 2019-09-27

Similar Documents

Publication Publication Date Title
US9208057B2 (en) Efficient model checking technique for finding software defects
CN104899147B (en) A kind of code Static Analysis Method towards safety inspection
US8132156B2 (en) Methods and systems for testing tool with comparative testing
US8539475B2 (en) API backward compatibility checking
CN109033843B (en) Java file dependency analysis method and module for distributed static detection system
CN110286912B (en) Code detection method and device and electronic equipment
US8312440B2 (en) Method, computer program product, and hardware product for providing program individuality analysis for source code programs
US9201757B2 (en) Offline type checking in programming languages
US9152731B2 (en) Detecting a broken point in a web application automatic test case
CN107832059B (en) Code static analysis method and device based on Makefile
CN110018954B (en) Code quality detection method, device and equipment, and code detection quality evaluation method, device and equipment
CN112100072A (en) Static detection method, device, equipment and medium for application program codes
KR101979329B1 (en) Method and apparatus for tracking security vulnerable input data of executable binaries thereof
CN117113347A (en) Large-scale code data feature extraction method and system
CN112925524A (en) Method and device for detecting unsafe direct memory access in driver
KR102546424B1 (en) Machine learning data generating apparatus, apparatus and method for analyzing errors in source code
CN115543781A (en) Method and interactive system for automatically verifying automobile software model
CN111258562B (en) Java code quality inspection method, device, equipment and storage medium
CN111309301B (en) Program language conversion method, device and conversion equipment
CN114895914A (en) Log output code generation method and device, electronic equipment and storage medium
US8819645B2 (en) Application analysis device
CN115543832A (en) Software code standard detection method, system, equipment and storage medium
CN115145575A (en) High-level language parsing method, equipment and computer readable storage medium
CN114691197A (en) Code analysis method and device, electronic equipment and storage medium
CN109597638B (en) Method and device for solving data processing and equipment linkage based on real-time computing engine

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
GR01 Patent grant
GR01 Patent grant