CN110286912A - Code detection method, device and electronic equipment - Google Patents

Code detection method, device and electronic equipment Download PDF

Info

Publication number
CN110286912A
CN110286912A CN201910597267.6A CN201910597267A CN110286912A CN 110286912 A CN110286912 A CN 110286912A CN 201910597267 A CN201910597267 A CN 201910597267A CN 110286912 A CN110286912 A CN 110286912A
Authority
CN
China
Prior art keywords
code
detected
error
error code
node
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.)
Granted
Application number
CN201910597267.6A
Other languages
Chinese (zh)
Other versions
CN110286912B (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

Abstract

The present invention provides a kind of code detection method, device and electronic equipments, are related to field of computer technology.This method comprises: being compiled using default compilation tool to code to be detected according to the error code rank divided in advance;If code compilation success to be detected, generative grammar tree;The each element of code to be detected is present in syntax tree in the form of node;Whole nodes of the syntax tree are traversed, to detect whether to obtain testing result with the presence of any level-one in node error code rank.The present invention realizes the complete detection to each rank mistake of code to be detected, can satisfy the detection demand to such special code such as AS3.

Description

Code detection method, device and electronic equipment
Technical field
The present invention relates to field of computer technology, more particularly, to a kind of code detection method, device and electronic equipment.
Background technique
In addition to the mainstreams code such as C++ in computer programming, there is also some more special codes, and many is at it The literary style that its mainstream speech is not supported can compile in such special code to be passed through.ActionScript3.0 code language Speech is the typical case of such special code, is illustrated by taking ActionScript3.0 (abbreviation AS3) code as an example below. It is its Flash product development that ActionScript, which is by Macromedia (being purchased by Adobe), is initially a kind of simple Scripting language, present latest edition ActionScript3.0, grammer is weaker to the constraint of literary style similar to JavaScript, Which results in the literary style disunity of each programmer, greatly reduces the readability of code, expansibility and can safeguard Property.Because Adobe will stop the maintenance of Flash, AS3 code is being bound in the future or is converting or be rewritten into other Languages. Therefore, currently it is necessary to carry out code detection to AS3, to guarantee that existing AS3 code met mainstream programming language writes habit Used and characteristic so as to AS3 code conversion in future or is rewritten into after mainstream programming language that there is no syntax errors.It has issued at present Code detection tool, be mainly based upon code complexity, code repeat the factors such as ratio and annotation ratio code is examined It surveys, is unable to satisfy the detection demand of such special code such as AS3.
Summary of the invention
The embodiment of the present invention is designed to provide a kind of code detection method, device and electronic equipment, and this method is realized To the complete detection of each rank mistake of code to be detected, can satisfy detection to such special code such as AS3 is needed It asks.
In a first aspect, the embodiment of the invention provides a kind of code detection methods, comprising: according to the wrong generation divided in advance Code rank, is compiled code to be detected using default compilation tool;If the code compilation success to be detected, generates Syntax tree;The each element of the code to be detected is present in the syntax tree in the form of node;Traverse the syntax tree All nodes, to detect whether to obtain detection knot with the presence of any level-one in the node error code rank Fruit.
With reference to first aspect, the embodiment of the invention provides the first possible embodiments of first aspect, wherein institute State method further include: the code rewriting to be detected that error code will be present is converted into target programmed language;After rewriting The compiling result of the code to be detected and the written in code specification of operation result and the target programmed language divide institute State error code rank;The target programmed language includes C language or C Plus Plus.
The possible embodiment of with reference to first aspect the first, the embodiment of the invention provides second of first aspect Possible embodiment, wherein the error code rank includes: first order error code, is when the first staging error generation When code is present in the revised code to be detected, the revised code compilation failure to be detected will lead to Error code;Second level error code, be when the second level error code be present in it is described revised described to be detected When code, the revised code compilation success to be detected but the error code of operation necessarily unsuccessfully can be made;The third level Error code is to make described change when the third level error code is present in the revised code to be detected The code compilation to be detected after writing is successful but there is the error code of operation failure probability;Fourth stage error code is to work as When the fourth stage error code is present in the revised code to be detected, it can make described revised described to be checked It surveys code compilation success and run successfully but operation result is wrong or null value error code;Level V error code is to work as When the level V error code is present in the revised code to be detected, it will not influence described revised described The compiling and operation of code to be detected, but do not meet the error code of the written in code specification of the target programmed language.
The possible embodiment of second with reference to first aspect, the embodiment of the invention provides the third of first aspect Possible embodiment, wherein the whole node of the traversal syntax tree, to detect whether with the presence of the node Any level-one in the error code rank, the step of obtaining testing result, comprising: preset detecting step is repeated, Until the whole nodal test in the syntax tree is completed;The detecting step includes: to choose appointing in the syntax tree One node detects the first node and other nodes being connected with the first node with the presence or absence of institute as first node Any one staging error code recorded in error code rank is stated, testing result is obtained.
The third possible embodiment with reference to first aspect, the embodiment of the invention provides the 4th kind of first aspect Possible embodiment, wherein the method also includes: if the testing result includes that there are the second staging error generations The log that reports an error is written, such as in the testing result by the node of code, the third level error code or the fourth stage error code Testing result described in fruit includes that prompt log is written in the testing result there are the node of the level V error code, And report an error log and/or prompt log output will be written with described in the testing result.
The possible embodiment of second with reference to first aspect, the embodiment of the invention provides the 5th kind of first aspect Possible embodiment, wherein the method also includes: if the code compilation failure to be detected, determines described to be detected There are the first order error codes in code, and the code information write-in of the code compilation failure to be detected will be caused to report an error day Will, and the log output that reports an error described in the code information for causing the code compilation failure to be detected will be written with.
With reference to first aspect or first aspect the first any one of to the 5th kind of possible embodiment, the present invention Embodiment provides the 6th kind of possible embodiment of first aspect, wherein the code to be detected is ActionScript3.0 code, the default compilation tool are flex-falcon.
Second aspect, the embodiment of the invention also provides a kind of code detecting apparatus, comprising: code compilation module is used for According to the error code rank divided in advance, code to be detected is compiled using default compilation tool;Syntax tree module is used In in the code compilation to be detected success, then generative grammar tree;The each element of the code to be detected is in the form of node It is present in the syntax tree;Detection module, the whole node for traversing the syntax tree are described to have detected whether Node obtains testing result there are any level-one in the error code rank.
The third aspect, the embodiment of the invention provides a kind of electronic equipment, including memory, processor, the memories In be stored with the computer program that can be run on the processor, wherein when the processor executes the computer program The step of realizing method as described in relation to the first aspect.
Fourth aspect, the embodiment of the invention provides a kind of computer-readable mediums, wherein the computer-readable medium Computer executable instructions are stored with, the computer executable instructions are when being called and being executed by processor, the computer Executable instruction promotes the method for the processor realization as described in relation to the first aspect.
The embodiment of the invention provides a kind of code detection method, device and electronic equipments, first, in accordance with what is divided in advance Error code rank is compiled code to be detected using default compilation tool;Secondly, if code compilation to be detected at Function, then generative grammar tree (each element of code to be detected is present in syntax tree in the form of node);Finally, traversal syntax tree Whole nodes, to detect whether to obtain testing result with the presence of any level-one in node error code rank.This method pair Code to be detected is compiled generative grammar tree, examines by whole nodes in traversal syntax tree, and based on error code rank Node is surveyed, can detecte out in syntax tree there are the node of all error code ranks, realize to each of code to be detected The complete detection of rank mistake can satisfy the detection demand to such special code such as AS3.
Other features and advantages of the present invention will illustrate in the following description, also, partly become from specification It obtains it is clear that understand through the implementation of the invention.The objectives and other advantages of the invention are in specification and attached drawing Specifically noted structure is achieved and obtained.
To enable the above objects, features and advantages of the present invention to be clearer and more comprehensible, preferred embodiment is cited below particularly, and cooperate Appended attached drawing, is described in detail below.
Detailed description of the invention
It, below will be to specific in order to illustrate more clearly of the specific embodiment of the invention or technical solution in the prior art Embodiment or attached drawing needed to be used in the description of the prior art be briefly described, it should be apparent that, it is described below Attached drawing is some embodiments of the present invention, for those of ordinary skill in the art, before not making the creative labor It puts, is also possible to obtain other drawings based on these drawings.
Fig. 1 is a kind of code detection method flow chart provided in an embodiment of the present invention;
Fig. 2 is a kind of code detection flow chart provided in an embodiment of the present invention;
Fig. 3 is a kind of code detecting apparatus structural schematic diagram provided in an embodiment of the present invention;
Fig. 4 is a kind of electronic equipment structural schematic diagram provided in an embodiment of the present invention.
Specific embodiment
Technical solution of the present invention is clearly and completely described below in conjunction with embodiment, it is clear that described reality Applying example is a part of the embodiment of the present invention, instead of all the embodiments.Based on the embodiments of the present invention, the common skill in this field Art personnel every other embodiment obtained without making creative work belongs to the model that the present invention protects It encloses.
In view of the code detection tool issued at present, it is mainly based upon code complexity, code repeats ratio and annotation The factors such as ratio detect code, are unable to satisfy the detection demand of such special code such as AS3.
Based on this, the embodiment of the invention provides a kind of code detection method, device and electronic equipment, this method by time Whole nodes in syntax tree are gone through, and are based on error code rank detection node, can detecte out wrong in the presence of institute in syntax tree The accidentally other node of code level, realizes the complete detection to each rank mistake of code to be detected, can satisfy to such as AS3 Etc. the detection demand of such special code.
For convenient for understanding the present embodiment, first to a kind of code detection method disclosed in the embodiment of the present invention into Row is discussed in detail.
Embodiment one:
A kind of code detection method provided in an embodiment of the present invention, referring to code detection method flow chart as shown in Figure 1, This method can be applied to the detection to ActionScript3.0 code, method includes the following steps:
S102: according to the error code rank divided in advance, code to be detected is compiled using default compilation tool.
Influence according to error code to code compilation operation result in advance divides the rank of error code, presses According to ready-portioned error level code rank, preset volume is added to using error code rank as the classification logic of error code It translates in tool and (can be and classification logic is added in compilation tool in the form of code), allow compilation tool according to above-mentioned Error code rank carries out level identification to the code of mistake, is compiled using preset compilation tool to code to be detected.
S104: if code compilation to be detected success, generative grammar tree;The each element of code to be detected is with the shape of node Formula is present in syntax tree.
If generating corresponding syntax tree, each member of code to code compilation to be detected success using compilation tool Element can exist in the form of node.Various types of nodes are present in compilation tool in the form of classes, each element of code Then become object relatively independent one by one, has the details of the node in object.The details packet of each node Contain: the file full path where node i d, nodal value, node type, node definition, father node object, child node object, the node Line number where diameter, the node.Therefore, by the information of some node, the detailed of all nodes of the whole story can be extrapolated Thin information.
S106: traversing whole nodes of syntax tree, to detect whether with the presence of any one in node error code rank Grade, obtains testing result.
After generative grammar tree, because error code rank is added to preset compiling work as the classification logic of error code In tool, compilation tool can analyze the grammer and structure of code by way of traverse node, to detect whether with the presence of node Any level-one in error code rank, that is, the corresponding code of each node is analyzed with the presence or absence of mistake, and identifies error The accidentally corresponding error code rank of code includes all codes that there is mistake in the testing result to obtain testing result And error code rank.
The embodiment of the invention provides a kind of code detection method, this method is compiled generative grammar to code to be detected Tree by whole nodes in traversal syntax tree, and is based on error code rank detection node, can detecte out in syntax tree and deposit In the node of all error code ranks, the complete detection to each rank mistake of code to be detected is realized, can satisfy To the detection demand of such special code such as AS3.
In view of every kind of code write specification or habit is different, some uncommon programming languages (code to be detected) if Target programmed language (common programming language) is converted or is rewritten into, must meet common programming language writes specification or habit It is used, then need to detect the code that do not supported by common programming language in uncommon programming language before conversion or rewriting, To detect the code in the presence of mistake before code conversion, on how to the other problem of partition error code level, the present embodiment Provide the other specific embodiment of partition error code level:
The code to be detected rewriting that error code will be present is converted into target programmed language;According to revised generation to be detected The compiling result of code and the written in code specification partition error code rank of operation result and target programmed language;Target is compiled Cheng Yuyan includes C language or C Plus Plus.In the rank of partition error code, the generation to be detected of error code will be present first Code is rewritten and is converted into target programmed language, which is common programming language or mainstream programming language, according to changing The compilation run knot of code to be detected (code namely to be detected, which is rewritten, is converted into the code after target programmed language) after writing The written in code specification partition error code rank of fruit and target programmed language.Such as the target programmed language can be C language Speech or C Plus Plus, C language or the C Plus Plus stringency in mainstream programming language be it is highest, therefore, with C language or C++ language The coding criterion of speech be foundation, it is ensured that code to be detected can easily transcription at various language.
In order to more protrude the difference between each staging error code, the specific interior of error code rank is present embodiments provided Hold, as shown in following first order error code to level V error code:
First order error code is will lead to and changes when first order error code is present in revised code to be detected The error code of code compilation to be detected failure after writing.First order error code is the mistake for leading to code there are greateset risk Code, and the characteristic that can not be supported in mainstream speech can not be compiled according to original code or after rewriting transcode By.For example, first order error code may is that the class name initial for not adding class name mark or type code is not big It writes;There is duplication of name member between father and son's class;A case has multiple break sentences in switch;Top function etc..
Second level error code is to make to rewrite when second level error code is present in revised code to be detected The error code that code compilation to be detected success but operation afterwards necessarily fails.Second level error code is the mistake when the rank When in the presence of with code, code compilation can be successfully passed, but collapse or stuck be inevitably resulted in after running, that is, run Necessarily fail.For example, second level error code is not write according to mainstream literary style when may is that XML initialization;Non- void is returned The function of value does not write return;Do not carry out type decision, directly change into other types by force, and call the type some at Member etc..
Third level error code is to make to rewrite when third level error code is present in revised code to be detected Code compilation to be detected afterwards is successful but there is the error code of operation failure probability.Third level error code is when the rank When mistake is existed with code, code compilation can be successfully passed, but may result in collapse or stuck after running, also It is the probability that fails there are certain operation.The key of Dictionary is claimed as moving for example, third level error code may is that State type;Array is not carried out to sentence sky, calls directly concat function etc..
Fourth stage error code is to make to rewrite when fourth stage error code is present in revised code to be detected Rear code compilation to be detected success and run successfully but operation result is wrong or null value error code.Fourth stage mistake generation Code is when the mistake of the rank exists with code, and code compilation can successfully pass, and when operation will not collapse, that is, transport Null value when going successfully, but the value of mistake can be obtained even.Regime type * is turned by force for example, fourth stage error code may is that For Vector;Dictionary type is used as regime type;Other attributes are called using match ();Array's Some value switchs to by force other types etc. using as.
Level V error code is will not influence when level V error code is present in revised code to be detected The compiling and operation of revised code to be detected, but do not meet the error code of the written in code specification of target programmed language. Level V error code can be successfully passed when compiling, running, and obtain when the mistake of the rank exists with code Correct operation result, but the error code of the written in code specification of target programmed language is not met, code writes not enough rule Model, it is readable poor, including two kinds of situations, one is, it is named using the keyword of mainstream speech, such as: TypeDef, asm, explicit, goto, register etc.;Another kind be do not meet mainstream speech coding criterion, such as: The naming method of various variable/functions is not according to hump principle;Constant names the principle for not using capitalization to underline;Not yet Have and sentences sky;Do not judge to cross the border;Do not increase abnormality processing;Annotation is very little or format is not right;Nested function literary style is lack of standardization etc..
In order to detect the mistake in code more fully hereinafter, whole nodes of traversal syntax tree are present embodiments provided, with It detects whether to obtain the specific embodiment of testing result with the presence of any level-one in node error code rank:
Preset detecting step is repeated, until whole nodal tests in syntax tree are completed;Detecting step includes: choosing Any node in syntax tree is taken as first node, whether detects first node and other nodes being connected with first node There are any one staging error codes recorded in error code rank, obtain testing result.When executing detecting step, a certain Code is written in the nodal test logic of seed type whether there is the logic (i.e. the classification logic of error code rank) of risk.Example Such as: cannot have non-override duplication of name member between father and son's class, then needing to pass through class section in the place of parsing class node Point searches class node and child class node, and analyzes and whether there is non-override duplication of name member inside found node, Log is reported an error or prompted in the presence of dividing to be added according to error level.In above-mentioned compilation tool generative grammar tree, according to wrong generation Each node in the classification logic traversal syntax tree of code rank chooses any node in syntax tree to execute detecting step As first node, since the details of each node include: node i d, nodal value, node type, node definition, father's section The line number where file full path diameter, the node where point object, child node object, the node, therefore, by obtaining first segment Point details, the details for all nodes being connected with first node can be extrapolated, according to first node and with Element in other connected nodes of first node, detection first node are appointed with the presence or absence of what is recorded in above-mentioned error level code Meaning level-one error code, to obtain testing result.
In order to more intuitively embody testing result, the present embodiment additionally provides the specific embodiment party of output test result Formula:
If testing result includes that there are second level error code, third level error code or fourth stage error codes Node will test result and the log that reports an error be written, if testing result includes that will test there are the node of level V error code As a result write-in prompt log, and report an error log and/or the prompt log output that testing result will be written with.If in testing result Including there are the node of second level error code, third level error code or fourth stage error code, i.e., being deposited in code to be detected In error code, which is second level error code, third level error code or fourth stage error code, due to second Staging error code, third level error code and fourth stage error code can have an impact the operation result of code, therefore, when out When existing second level error code, third level error code or fourth stage error code, it will do it code and report an error, will test result and write Enter the log that reports an error, which is to cause code operation failure or the code information of operation result mistake to be detected, and will write Enter to have the log output that reports an error of testing result, so that user can be to be detected according to the error code modification recorded in the log that reports an error Mistake in code.If testing result includes there is mistake in code that is, to be detected there are the node of level V error code Accidentally code, which is level V error code, since level V error code will not generate the operation result of code It influences, therefore, when there is level V error code, result write-in prompt log can be will test, will not be advised present in code Model literary style shows user in the form of prompting log, so that user can write according to what is recorded in prompt log there are lack of standardization Existing code literary style lack of standardization in the code revision of method code to be detected.
The case where will appear compiling failure in view of code to be detected, present embodiments provide a kind of code compilation to be detected Specific embodiment after failure:
If code compilation failure to be detected, determines that there are first order error codes in code to be detected, will cause to be checked The log that reports an error is written in the code information for surveying code compilation failure, and will be written with and the code of code compilation failure to be detected is caused to be believed The log output that reports an error of breath.It is to be checked if occurring the case where compiling failure when using compilation tool to code compilation to be detected Surveying error code present in code is first order error code, and the code information of code compilation failure to be detected will be caused to be written Report an error log, and the log output that reports an error that will be written with the code information for causing code compilation failure to be detected, so as to user's root According to the code information for causing code compilation failure to be detected recorded in the log that reports an error, change tape detects the wrong generation in code Code.
In view of the application of above-mentioned code detection method in practice, code to be detected is ActionScript3.0 code, Default compilation tool is flex-falcon.Flex is an efficient, free Open Framework, and can be used for constructing has expressive force Web application, these application programs utilize Adobe Flash Player and Adobe AIR, may be implemented browser-cross, Desktop and operating system.Flex-falcon is the newly compiled device for being Flex, in the present embodiment can using flex-falcon as Default compilation tool.Since Adobe will stop the maintenance of Flash, ActionScript3.0 (abbreviation AS3) code is being incited somebody to action To be bound to or convert or be rewritten into other Languages.Therefore, before these work start, need to guarantee that AS3 code meets master Stream language writes habit and characteristic, therefore above-mentioned code detection method can be used for the inspection to ActionScript3.0 code Survey, to detect the characteristic that do not supported by mainstream programming language in AS3, and do not meet mainstream programming language coding habit with Specification.
In practical applications, as a kind of feasible embodiment, code detection flow chart as shown in Figure 2 is starting When carrying out code detection, the program of compilation tool is initialized first, code to be detected is compiled using compilation tool, if Compiling can then not reported an error by (i.e. compiling failure), and compiling is not the first order by error code present in then code to be detected Error code will cause the code information write-in of code compilation failure to be detected to report an error log (error log i.e. in figure).Such as Fruit compiling passes through (compiling successfully) then generative grammar tree, and the classification of ready-portioned error code is added in compilation tool (i.e. Addition rule in figure), syntax tree then is parsed by way of the node in traversal syntax tree, to have detected whether that node is deposited Any level-one in error code rank judges wrong with the presence or absence of level V code in code to be detected in detection node Accidentally, that is, whether there is the nonstandard prompt of code, if testing result include there are the node of level V error code, Exist in code i.e. to be detected do not meet target programmed language write specification, by literary style lack of standardization present in code to prompt The form of log shows user, judges whether being parsed to syntax tree whole node, if it is, terminating to detect Journey, if it is not, then judging in code to be detected with the presence or absence of second level error code, third level error code or fourth stage mistake Code;If there is no the nonstandard prompt of code, also judge in code to be detected with the presence or absence of second level error code, the Three-level error code or fourth stage error code, due to second level error code, third level error code and fourth stage mistake generation Code can have an impact the operation result of code, therefore, second level error code, third level error code or the occur when determining It when level Four error code, can report an error to error code, will test result write-in and report an error log (alternatively referred to as error log), Code detection process terminates.
The embodiment of the invention provides a kind of code detection methods, are classified by partition error code, have formulated strict It is classified logic, then by traverse node and syntactic analysis, code syntax and code hidden danger etc. are comprehensively detected, this method It can be applied to the scenes such as code inspection, exploitation self-test, code upgrade.And code detection method provided in this embodiment generates report Wrong log and prompt log, intuitively show user for mistake present in code, modify the error code side of providing for user Just.
Embodiment two:
The embodiment of the invention provides a kind of code detecting apparatus, referring to a kind of code detecting apparatus knot as shown in Figure 3 Structure schematic diagram, the device include:
Code compilation module 31, for according to the error code rank divided in advance, using default compilation tool to be checked Code is surveyed to be compiled.
Syntax tree module 32 is used in code compilation to be detected success, then generative grammar tree;Each member of code to be detected Element is present in syntax tree in the form of node.
Detection module 33, for traversing whole nodes of syntax tree, to detect whether with the presence of node error code rank In any level-one, obtain testing result.
In one embodiment, above-mentioned apparatus further include:
Partition of the level module, the code to be detected for error code to will be present, which is rewritten, is converted into target programmed language;Root It is divided according to the compiling result and operation result of revised code to be detected and the written in code specification of target programmed language wrong Accidentally code rank;Target programmed language includes C language or C Plus Plus.
In one embodiment, the ready-portioned error code rank of above-mentioned partition of the level module are as follows:
First order error code is will lead to and changes when first order error code is present in revised code to be detected The error code of code compilation to be detected failure after writing.
Second level error code is to make to rewrite when second level error code is present in revised code to be detected The error code that code compilation to be detected success but operation afterwards necessarily fails.
Third level error code is to make to rewrite when third level error code is present in revised code to be detected Code compilation to be detected afterwards is successful but there is the error code of operation failure probability.
Fourth stage error code is to make to rewrite when fourth stage error code is present in revised code to be detected Rear code compilation to be detected success and run successfully but operation result is wrong or null value error code.
Level V error code is will not influence when level V error code is present in revised code to be detected The compiling and operation of revised code to be detected, but do not meet the error code of the written in code specification of target programmed language.
In one embodiment, above-mentioned detection module 33 is further used for, and repeats preset detecting step, until Whole nodal tests in syntax tree are completed;Detecting step includes: to choose any node in syntax tree as first node, is examined It is wrong with the presence or absence of any level-one recorded in error code rank to survey first node and other nodes being connected with first node Accidentally code, obtains testing result.
In one embodiment, above-mentioned apparatus further include:
Journal output module, for testing result include there are second level error code, third level error code or When the node of fourth stage error code, it will test result and the log that reports an error be written, include that there are level V mistakes in testing result When the node of code, result write-in prompt log, and report an error log and/or the prompt log that testing result will be written with will test Output.
Compiling failure module, in code compilation to be detected failure, determining that there are first order mistakes in code to be detected Accidentally code will cause the code information of code compilation failure to be detected that the log that reports an error is written, and will be written with and cause generation to be detected The log output that reports an error of the code information of code compiling failure.
In one embodiment, the code to be detected mentioned in above-mentioned apparatus is ActionScript3.0 code, is preset Compilation tool is flex-falcon.
The embodiment of the invention provides a kind of code detecting apparatus, have with the code detection method that above-described embodiment one provides There is identical technical characteristic, so also can solve identical technical problem, reaches identical technical effect.
The technical effect of device provided by the present embodiment, realization principle and generation is identical with previous embodiment, for letter It describes, Installation practice part does not refer to place, can refer to corresponding contents in preceding method embodiment.
Embodiment three:
A kind of electronic equipment provided in an embodiment of the present invention, electronic devices structure schematic diagram as shown in Figure 4, electronic equipment Including processor 41, memory 42, the computer program that can be run on the processor is stored in the memory, it is described Processor realizes the step of method that above-described embodiment one provides when executing the computer program.
Referring to fig. 4, electronic equipment further include: bus 44 and communication interface 43, processor 41, communication interface 43 and memory 42 are connected by bus 44.Processor 41 is for executing the executable module stored in memory 42, such as computer program.
Wherein, memory 42 may include high-speed random access memory (RAM, Random Access Memory), It may further include nonvolatile memory (non-volatile memory), for example, at least a magnetic disk storage.By at least One communication interface 43 (can be wired or wireless) realizes the communication between the system network element and at least one other network element Connection, can be used internet, wide area network, local network, Metropolitan Area Network (MAN) etc..
Bus 44 can be ISA (Industry Standard Architecture, industry standard architecture) bus, PCI (Peripheral Component Interconnect, Peripheral Component Interconnect standard) bus or EISA (Extended Industry Standard Architecture, expanding the industrial standard structure) bus etc..It is total that the bus can be divided into address Line, data/address bus, control bus etc..Only to be indicated with a four-headed arrow in Fig. 4, it is not intended that only one convenient for indicating Root bus or a type of bus.
Wherein, memory 42 is for storing program, and the processor 41 executes the journey after receiving and executing instruction Sequence, method performed by the device that the stream process that aforementioned any embodiment of the embodiment of the present invention discloses defines can be applied to handle In device 41, or realized by processor 41.
Processor 41 may be a kind of IC chip, the processing capacity with signal.During realization, above-mentioned side Each step of method can be completed by the integrated logic circuit of the hardware in processor 41 or the instruction of software form.Above-mentioned Processor 41 can be general processor, including central processing unit (Central Processing Unit, abbreviation CPU), network Processor (Network Processor, abbreviation NP) etc..It can also be digital signal processor (Digital Signal Processing, abbreviation DSP), specific integrated circuit (Application Specific Integrated Circuit, referred to as ASIC), ready-made programmable gate array (Field-Programmable Gate Array, abbreviation FPGA) or other are programmable Logical device, discrete gate or transistor logic, discrete hardware components.It may be implemented or execute in the embodiment of the present invention Disclosed each method, step and logic diagram.General processor can be microprocessor or the processor is also possible to appoint What conventional processor etc..The step of method in conjunction with disclosed in the embodiment of the present invention, can be embodied directly in hardware decoding processing Device executes completion, or in decoding processor hardware and software module combination execute completion.Software module can be located at Machine memory, flash memory, read-only memory, programmable read only memory or electrically erasable programmable memory, register etc. are originally In the storage medium of field maturation.The storage medium is located at memory 42, and processor 41 reads the information in memory 42, in conjunction with Its hardware completes the step of above method.
Example IV:
A kind of computer-readable medium provided in an embodiment of the present invention, wherein the computer-readable medium storage has meter Calculation machine executable instruction, when being called and being executed by processor, the computer is executable to be referred to the computer executable instructions Order promotes the processor to realize method described in embodiment one.
Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention., rather than its limitations;To the greatest extent Pipe present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that: its according to So be possible to modify the technical solutions described in the foregoing embodiments, or to some or all of the technical features into Row equivalent replacement;And these are modified or replaceed, various embodiments of the present invention technology that it does not separate the essence of the corresponding technical solution The range of scheme.

Claims (10)

1. a kind of code detection method characterized by comprising
According to the error code rank divided in advance, code to be detected is compiled using default compilation tool;
If the code compilation success to be detected, generative grammar tree;The each element of the code to be detected is with the shape of node Formula is present in the syntax tree;
The whole node of the syntax tree is traversed, to detect whether with the presence of in the node error code rank Any level-one, obtains testing result.
2. the method according to claim 1, wherein the method also includes:
The code rewriting to be detected that error code will be present is converted into target programmed language;
According to the code of the compiling result of the revised code to be detected and operation result and the target programmed language It writes specification and divides the error code rank;The target programmed language includes C language or C Plus Plus.
3. according to the method described in claim 2, it is characterized in that, the error code rank includes:
First order error code, be when the first order error code is present in the revised code to be detected, It will lead to the error code of the revised code compilation failure to be detected;
Second level error code, be when the second level error code is present in the revised code to be detected, The error code that the revised code compilation success to be detected but operation can be made necessarily to fail;
Third level error code, be when the third level error code is present in the revised code to be detected, It can make the revised code compilation success to be detected but there is the error code of operation failure probability;
Fourth stage error code, be when the fourth stage error code is present in the revised code to be detected, It can make the revised code compilation to be detected success and run successfully but operation result is wrong or the mistake of null value Code;
Level V error code, be when the level V error code is present in the revised code to be detected, It will not influence the compiling and operation of the revised code to be detected, but do not meet the code of the target programmed language Write the error code of specification.
4. according to the method described in claim 3, it is characterized in that, the whole node of the traversal syntax tree, with The step of detecting whether with the presence of any level-one in the node error code rank, obtaining testing result, comprising:
Preset detecting step is repeated, until the whole nodal test in the syntax tree is completed;The detection step Suddenly include: to choose any node in the syntax tree as first node, detect the first node and with described first Other connected nodes of node obtain detection knot with the presence or absence of any one staging error code recorded in the error code rank Fruit.
5. according to the method described in claim 4, it is characterized in that, the method also includes:
If the testing result includes that there are the second level error codes, the third level error code or the described 4th The node of staging error code reports an error the testing result write-in log, if the testing result includes that there are described the Prompt log, and the report that will be written with the testing result is written in the testing result by the node of Pyatyi error code Wrong log and/or prompt log output.
6. according to the method described in claim 3, it is characterized in that, the method also includes:
If the code compilation failure to be detected, determine that there are the first order error codes in the code to be detected, it will Cause the code information write-in of the code compilation to be detected failure to report an error log, and will be written with it is described cause it is described to be detected The log output that reports an error of the code information of code compilation failure.
7. method according to any one of claims 1 to 6, which is characterized in that the code to be detected is ActionScript3.0 code, the default compilation tool are flex-falcon.
8. a kind of code detecting apparatus characterized by comprising
Code compilation module, for according to the error code rank divided in advance, using default compilation tool to code to be detected It is compiled;
Syntax tree module is used in the code compilation to be detected success, then generative grammar tree;The code to be detected it is each Element is present in the syntax tree in the form of node;
Detection module, the whole node for traversing the syntax tree, to detect whether with the presence of the node mistake Accidentally any level-one in code rank, obtains testing result.
9. a kind of electronic equipment, including memory, processor, be stored in the memory to run on the processor Computer program, which is characterized in that the processor realizes that the claims 1 to 7 are any when executing the computer program The step of method described in item.
10. a kind of computer-readable medium, which is characterized in that the computer-readable medium storage has computer is executable to refer to It enables, for the computer executable instructions when being called and being executed by processor, the computer executable instructions promote the place It manages device and realizes the described in any item methods of claim 1 to 7.
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 true CN110286912A (en) 2019-09-27
CN110286912B 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)

Cited By (2)

* 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
CN113031940A (en) * 2021-04-29 2021-06-25 武汉夜莺科技有限公司 Front-end framework development method and device and terminal equipment

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

Cited By (2)

* 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
CN113031940A (en) * 2021-04-29 2021-06-25 武汉夜莺科技有限公司 Front-end framework development method and device and terminal equipment

Also Published As

Publication number Publication date
CN110286912B (en) 2023-08-18

Similar Documents

Publication Publication Date Title
US8151276B2 (en) Test script transformation analyzer with change guide engine
US8458662B2 (en) Test script transformation analyzer with economic cost engine
US8875110B2 (en) Code inspection executing system for performing a code inspection of ABAP source codes
US9146712B2 (en) Extensible code auto-fix framework based on XML query languages
US6941546B2 (en) Method and apparatus for testing a software component using an abstraction matrix
US8312440B2 (en) Method, computer program product, and hardware product for providing program individuality analysis for source code programs
US20130239098A1 (en) Source code conversion method and source code conversion program
US20090217302A1 (en) Test script transformation architecture
US20110010644A1 (en) User interface indicators for changed user interface elements
US20090217250A1 (en) Graphical user interface metadata evolution tool
US9304893B1 (en) Integrated software development and test case management system
US10459829B2 (en) Overall test tool migration pipeline
CN111694746A (en) Flash defect fuzzy evaluation tool for compilation type language AS3
CN110286912A (en) Code detection method, device and electronic equipment
EP2105837B1 (en) Test script transformation analyzer with change guide engine
KR102546424B1 (en) Machine learning data generating apparatus, apparatus and method for analyzing errors in source code
CN115291854A (en) Code completion method, device and equipment
CN107797805A (en) A kind of code wrap method, apparatus and computer-readable recording medium
CN107153610A (en) A kind of program statement error-detecting method and device
Berkenkötter Reliable UML models and profiles
Mottu et al. Discovering model transformation pre-conditions using automatically generated test models
US8819645B2 (en) Application analysis device
CN114895914A (en) Log output code generation method and device, electronic equipment and storage medium
CN115145575A (en) High-level language parsing method, equipment and computer readable storage medium
Landhaußer et al. DeNom: a tool to find problematic nominalizations using NLP

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