Method for extracting C language feature code
By defining and analyzing C language features, building feature analysis templates and extracting feature codes, the problem of identifying feature codes in C language structures in airworthiness standards is solved, and efficient analysis efficiency and strong versatility feature code extraction methods are achieved.
Patent Information
- Application Number
- CN202411679196.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-02-28
AI Technical Summary
In the airworthiness standard DO-178C, additional code generated by A-level software-level compilers or linkers that cannot directly trace the source code, resulting in difficulty in verification, especially lack of effective methods for identifying feature codes representing the C-language structure.
By defining the features of C language, building a feature analysis template, and extracting the code based on the template, identifying feature codes that can completely represent the characteristics of the programming language. The specific steps include defining features such as data structures, operators, function calls, etc., building feature analysis templates, analyzing function statements line by line, summarizing feature information, and selecting functions covering all features as feature codes.
It realizes effective extraction of C language feature code, reduces the scope of traceability analysis of source code and target code, improves analysis efficiency, and is suitable for all C language development projects, and has strong versatility.
Smart Images

Figure CN119536802A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of civil aviation engine control software, and in particular to a method for extracting C language feature codes. Background Art
[0002] In the airworthiness standard "Software Considerations in Airborne Systems and Equipment Certification" (DO-178C) in 6.4.4.2 Structural Coverage Analysis, if the software level is A, and the compiler, linker, or other methods generate additional code that cannot be directly traced to source code statements, additional verification should be carried out to prove the correctness of the generated code sequence. Table A-7 Objective 9 requires the completion of verification of additional code that cannot be traced to the source code. In 4.12 DP#12 of DO248C, a traceability analysis method is provided, which is to identify feature codes that fully represent the application language structure and analyze the generated target code. If the comparison performed on the feature code shows no functional differences, it means that the target code does not contain additional functions. For programs developed in C language, there is no method provided on how to identify feature codes representing C language structures. Summary of the invention
[0003] Purpose of the invention: The purpose of the present invention is to provide a method for extracting feature codes of C language, which supports programs developed using C language programs to identify feature codes that can fully represent the characteristics of the program language by performing feature generation extraction.
[0004] Technical solution: The method for extracting C language feature codes described in the present invention comprises the following steps: (1) Define the characteristics of C language based on its features; (2) Construct a C language feature analysis template; (3) Extract the code based on the C language feature analysis template.
[0005] Furthermore, in step (1), the characteristics of the C language are defined from the perspectives of data structure, operator, function call, preprocessing, and program control; wherein the data structure includes: basic type, constructed type, void type, pointer type, and forced type conversion; and the constructed type includes three types: array, union, and structure.
[0006] Furthermore, in step (2), when feature analysis is performed on a function basis, the function statements are analyzed line by line from eight areas: return type, function name, parameter type, basic type within the function body, constructed type within the function body, preprocessing within the function, operator within the function, and process control within the function. The types used are filled in the corresponding areas according to the feature names defined in step (1).
[0007] Furthermore, step (3) is as follows: first, analyze the functions of each C file according to the feature analysis template; second, summarize the feature analysis results of all C files, delete duplicate features in the same area of the template, and form a feature summary; finally, according to the feature summary table, select functions that can cover the features until all features are fully covered. The selected functions are the feature codes.
[0008] The present invention provides a system for extracting C language feature codes, comprising: Definition module: used to define the characteristics of C language according to the characteristics of C language; Analysis module: used to build C language feature analysis template; Extraction module: used to extract code based on C language feature analysis template.
[0009] Furthermore, in the definition module, the characteristics of C language are defined from data structure, operator, function call, preprocessing, and program control; among them, the data structure includes: basic type, constructed type, void type, pointer type, and forced type conversion; the constructed type includes three types: array, union, and structure.
[0010] Furthermore, when performing feature analysis on functions as units, the function statements are analyzed line by line from eight areas: return type, function name, parameter type, basic type within the function body, constructed type within the function body, preprocessing within the function, operator within the function, and process control within the function. The types used are filled in the corresponding areas according to the feature names defined in the definition module.
[0011] Furthermore, the extraction module is specifically as follows: first, the functions of each C file are analyzed according to the feature analysis template; secondly, the feature analysis results of all C files are summarized, and duplicate features in the same area of the template are deleted to form a feature summary; finally, according to the feature summary table, functions that can cover the features are selected until all features are fully covered, and the selected functions are the feature codes.
[0012] An electronic device described in the present invention includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is loaded into the processor, any one of the methods for extracting C language feature codes is implemented.
[0013] A storage medium described in the present invention stores a computer program, and when the computer program is executed by a processor, any one of the methods for extracting C language feature codes is implemented.
[0014] Beneficial effects: Compared with the prior art, the present invention has the following significant advantages: the selected feature codes are used as a subset of the project, the scope of source code and target code traceability analysis is reduced, and the analysis efficiency is improved; it can be applied to all C language development projects and has strong versatility; it can be used as a reference for other languages. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 is a flow chart of the present invention; Figure 2 It is the feature analysis template diagram of the present invention. DETAILED DESCRIPTION
[0016] The technical solution of the present invention is further described below in conjunction with the accompanying drawings.
[0017] like Figure 1 As shown, an embodiment of the present invention provides a method for extracting C language feature codes, comprising the following steps: (1) Define the characteristics of C language according to its features; specifically, define the characteristics of C language from the perspectives of data structure, operator, function call, preprocessing, and program control; data structure includes basic type, constructed type, void type, pointer type, and forced type conversion; constructed type includes array, union, and structure.
[0018] (2) Construct a C language feature analysis template; the details are as follows: Figure 2 As shown in the figure, when performing feature analysis on a function basis, the eight areas of return type, function name, parameter type, basic type in the function body, constructed type in the function body, preprocessing in the function, operator in the function, and process control in the function are analyzed line by line. The types used are filled in the corresponding areas according to the feature names defined in step (1).
[0019] (3) Extract the code according to the C language feature analysis template. The details are as follows: First, analyze the functions of each C file according to the feature analysis template; second, summarize the feature analysis results of all C files, delete duplicate features in the same area of the template, and form a feature summary; finally, according to the feature summary table, select functions that can cover the features until all features are fully covered. The selected functions are the feature codes. The details are as follows: Use the Excel table template for feature analysis to perform feature analysis on functions one by one, summarize the features of all functions into a large table. The summary table is consistent with the regional division of the feature analysis, delete the duplicates in the corresponding area, and uniquely number each feature in each area.
[0020] After the feature summary table is established, the process of selecting C language feature codes begins. The specific selection method is as follows: a) From the list of code features used in the project, select a code feature that has not been covered (for the first selection, no C language code feature is covered); b) Select a function that contains the code feature and record it in the feature code subset; c) According to the code features used by the function, the corresponding code features are marked as covered; d) Check the code feature list to see if all code features have been marked as covered. If there are still uncovered code features, return to step a) and continue selecting until all features are marked as covered; e) Arrange the selected feature code subset functions, establish the code feature relationship covered by each function, and the relationship between each code feature and the covered function.
[0021] The embodiment of the invention provides a system for extracting C language feature codes, including: Definition module: used to define the characteristics of C language according to the characteristics of C language; specifically: define the characteristics of C language from data structure, operator, function call, preprocessing, and program control; data structure includes: basic type, structure type, empty type, pointer type, and forced type conversion; structure type includes three types: array, union, and structure Analysis module: used to construct a C language feature analysis template; specifically, when performing feature analysis on a function basis, analyze the function statements line by line from eight areas: return type, function name, parameter type, basic type within the function body, constructed type within the function body, preprocessing within the function, operator within the function, and process control within the function. Fill in the used types in the corresponding areas according to the feature names defined in the definition module.
[0022] Extraction module: used to extract code according to the C language feature analysis template. The details are as follows: first, analyze the functions of each C file according to the feature analysis template; second, summarize the feature analysis results of all C files, delete duplicate features in the same area of the template, and form a feature summary; finally, according to the feature summary table, select functions that can cover the features until all features are fully covered. The selected functions are the feature codes.
[0023] An embodiment of the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the computer program is loaded into the processor, any one of the methods for extracting C language feature codes is implemented.
[0024] An embodiment of the present invention further provides a storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the computer program implements any one of the methods for extracting C language feature codes.
Claims
1. A method for extracting C language feature codes, characterized in that: The following steps are involved: (1) Define the characteristics of C language based on its features; (2) Construct a C language feature analysis template; (3) Extract the code based on the C language feature analysis template.
2. A method for extracting C language feature codes according to claim 1, characterized in that: In step (1), the characteristics of C language are defined from data structure, operator, function call, preprocessing, and program control; wherein data structure includes: basic type, constructed type, void type, pointer type, and forced type conversion; constructed type includes three types: array, union, and structure.
3. According to the method for extracting C language feature codes as described in claim 1, in step (2), when performing feature analysis on a function basis, the statements of the function are analyzed line by line from eight areas: return type, function name, parameter type, basic type within the function body, construction type within the function body, preprocessing within the function, operator within the function, and process control within the function, and the types used are filled in the corresponding areas according to the feature names defined in step (1).
4. According to the method for extracting C language feature codes as described in claim 1, step (3) is specifically as follows: first, the functions of each C file are analyzed according to the feature analysis template; secondly, the feature analysis results of all C files are summarized, and repeated features in the same area in the template are deleted to form a feature summary; finally, according to the feature summary table, functions that can cover the features are selected until all features are fully covered, and the selected functions are the feature codes.
5. A system for extracting C language feature codes, characterized in that: include: Definition module: used to define the characteristics of C language according to the characteristics of C language; Analysis module: used to build C language feature analysis template; Extraction module: used to extract code based on C language feature analysis template.
6. A system for extracting C language feature codes according to claim 5, characterized in that: In the definition module, the characteristics of C language are defined from data structure, operator, function call, preprocessing, and program control; among them, data structure includes: basic type, constructed type, void type, pointer type, and forced type conversion; constructed type includes three types: array, union, and structure.
7. According to the extraction system for C language feature code described in claim 5, in the analysis module, when performing feature analysis with functions as units, the function statements are analyzed line by line from eight areas: return type, function name, formal parameter type, basic type in the function body, construction type in the function body, preprocessing in the function, operator in the function, and process control in the function. The types used are filled in the corresponding areas according to the feature names defined in the definition module.
8. According to the extraction system for C language feature codes described in claim 5, the specific operations in the extraction module are as follows: first, the functions of each C file are analyzed according to the feature analysis template; secondly, the feature analysis results of all C files are summarized, and repeated features in the same area in the template are deleted to form a feature summary; finally, according to the feature summary table, functions that can cover the features are selected until all features are fully covered, and the selected functions are the feature codes.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the computer program is loaded into a processor, a method for extracting C language feature codes according to any one of claims 1 to 4 is implemented.
10. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, a method for extracting C language feature codes according to any one of claims 1 to 4 is implemented.