CN116594687A - Cross-platform transplanting system and transplanting method for C language source codes - Google Patents

Cross-platform transplanting system and transplanting method for C language source codes Download PDF

Info

Publication number
CN116594687A
CN116594687A CN202310511500.0A CN202310511500A CN116594687A CN 116594687 A CN116594687 A CN 116594687A CN 202310511500 A CN202310511500 A CN 202310511500A CN 116594687 A CN116594687 A CN 116594687A
Authority
CN
China
Prior art keywords
rule
file
language
module
transplanting
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310511500.0A
Other languages
Chinese (zh)
Inventor
张余超
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Qingdao Benyuan Microelectronics Co ltd
Original Assignee
Qingdao Benyuan Microelectronics 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 Qingdao Benyuan Microelectronics Co ltd filed Critical Qingdao Benyuan Microelectronics Co ltd
Priority to CN202310511500.0A priority Critical patent/CN116594687A/en
Publication of CN116594687A publication Critical patent/CN116594687A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/76Adapting program code to run in a different environment; Porting
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • 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)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a C language source code cross-platform transplanting system and a transplanting method, wherein the system comprises a rule module, a verification module, a C language code analysis module and an execution module; the rule module is used for analyzing the rule file and converting the transplanting rules in the rule file into a data structure; the checking module is used for checking whether the C language code file and the rule file exist or not, if not, reporting errors and terminating operation; checking whether the target file can be created or not, if not, reporting errors and terminating operation; the C language code analysis module is used for reading the content of the C language file and judging the sentence type of each C language sentence; the execution module is used for executing the transplanting operation according to the statement type and the transplanting rule. The transplanting system and the transplanting method disclosed by the invention have the advantages of easy modification, flexibility and high efficiency, support of bidirectional transplanting between operating systems and bidirectional transplanting between different architecture hardware, and have wide application range and universality.

Description

Cross-platform transplanting system and transplanting method for C language source codes
Technical Field
The invention relates to a software transplanting method and a system, in particular to a C language source code cross-platform transplanting system and a transplanting method.
Background
When migrating source code written in the C language from one platform to another, a method of converting the characteristics of the original platform into the support of the new platform is required. The content to be modified in the source code is more, the workload is larger, the manual conversion efficiency is low, the possibility of incorrect operation exists, and the problems are well solved by using a transplanting system.
The traditional conversion system is only suitable for unidirectional conversion between two fixed platforms, has no universality, and in addition, the source code of the conversion system is modified each time a new conversion rule is added, and then the conversion system is compiled to generate a new version conversion system, so that the expansibility is poor.
Disclosure of Invention
In order to solve the technical problems, the invention provides a cross-platform transplanting system and a cross-platform transplanting method for C language source codes, so as to achieve the purposes of flexibility, high efficiency and universality.
In order to achieve the above purpose, the technical scheme of the invention is as follows:
a cross-platform transplanting system for a C language source code comprises a rule module, a verification module, a C language code analysis module and an execution module;
the rule module is used for analyzing the rule file, converting the transplanting rule in the rule file into a data structure, and storing the data structure into a computer memory for subsequent use;
the checking module is used for checking whether the C language code file and the rule file exist or not, if not, reporting errors and terminating operation; checking whether the target file can be created or not, if not, reporting errors and terminating operation;
the C language code analysis module is used for reading the content of the C language file and judging the sentence type of each C language sentence;
the execution module is used for acquiring the transplanting rule of the sentence type from the rule module according to the sentence type analyzed by the C language code analysis module; checking whether the content to be matched in each migration rule is matched with the content of the current C language code sentence, if so, executing the operation of the migration rule, and outputting the executed content to the target file.
In the above scheme, a plurality of migration rules are defined in the rule file, and the migration rules describe contents to be matched and operations to be performed on the contents.
In the above scheme, the rule module defines rule types, and the rule types include a new class rule, an annotation class rule, a replacement class rule and a deletion class rule.
In a further technical scheme, the new added type rule includes operation type, added content, added position and execution times information.
In a further technical scheme, the annotation class rule comprises operation type, execution object, execution times, matching templates and matching type information.
In a further technical scheme, the replacement class rule comprises operation types, execution objects, execution times, matching templates and target template information.
In a further technical scheme, the deletion class rule comprises an operation type, an execution object, execution times, a matching template and matching type information.
A cross-platform transplanting method for C language source codes adopts the cross-platform transplanting system for C language source codes, which comprises the following steps:
when the system operates, firstly, a user is required to specify a rule file, a C language file and a transplanted target file path;
then, the checking module checks whether the C language file and the rule file appointed by the user exist or not, if not, the error is reported, and the transplanting system terminates operation; then testing whether the target file can be created, if the target file fails, reporting errors, and terminating the operation of the transplanting system;
the rule module analyzes the rule file, analyzes the rule from the text description into a data structure, namely rule class object data, stores the rule class object data into a rule Map according to the classification of an execution object, and provides rules of specified sentence types for other modules;
the C language code analysis module reads the content of the C language file and executes the following operations on each row of content: judging whether the current content is an annotation or not, and outputting the annotation to a target file if the current content is the annotation; if the annotation is not the annotation, firstly eliminating the annotation in the content, and then judging the type of the annotation; if the type cannot be judged, carrying out statement type analysis by combining the next row of content of the C language file until the statement type is determined; transmitting the statement and statement type information to an execution module;
the execution module acquires the transplanting rules of the sentence type from the rule module according to the sentence type, screens and reserves the transplanting rules with the actual execution times smaller than the execution times, and then executes the following operations on each rule:
checking whether a matching template in the rule matches statement content, if so, executing the operation of the rule, outputting the executed content to a target file, and recording the actual execution times of the rule plus one; if not, not processing;
after the execution module processes the whole C language file, the execution module saves the target file, and the operation of the transplanting system is finished.
Through the technical scheme, the cross-platform transplanting system and the transplanting method for the C language source code have the following beneficial effects:
1. when a new transplanting rule is found, the transplanting system code is not required to be modified and recompiled, and only the new rule is required to be defined in the rule file of the rule module, so that the method has the advantages of easy modification, flexibility and high efficiency.
2. Compared with the limitation that the conventional transplanting system can only carry out unidirectional transplanting on two fixed platforms, the method not only supports bidirectional transplanting between operating systems, but also supports bidirectional transplanting between different architecture hardware, has wide application range and is more universal.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below.
Fig. 1 is a schematic diagram of a cross-platform migration system for C-language source code according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
The invention provides a cross-platform transplanting system for a C language source code, which is shown in figure 1 and comprises a rule module, a verification module, a C language code analysis module and an execution module. In this embodiment, the migration system is written in the Java language.
The rule module is used for analyzing the rule file, converting the transplanting rule in the rule file into a data structure, and storing the data structure into a computer memory, so that the follow-up use is facilitated; a number of migration rules are defined in the rule file, which describe the content to be matched and the operations to be performed on them.
Rule types are defined in the rule module, as shown in table 1, and include an add class rule, an annotate class rule, a replace class rule, and a delete class rule. The newly added class rule comprises information such as operation type, added content, added position, execution times and the like. The annotation class rule comprises information such as operation type, execution object, execution times, matching template, matching type and the like. The replacement class rule comprises information such as operation type, execution object, execution times, matching template, target template and the like. The deletion class rule comprises information such as operation type, execution object, execution times, matching template, matching type and the like. Wherein "operation type" indicates the operation type of the current rule; "execution object" means the sentence type of the C language; "number of executions" means the number of executions of the rule; "match templates" support regular expressions, representing templates that match the C language code; the "target template" supports regular expressions, representing how to edit the C language code; "match type" indicates whether a partial match or a complete match; "addition position" means an insertion position.
TABLE 1 rule types
The checking module is used for checking whether the C language code file and the rule file exist or not, if not, reporting errors and terminating operation; and checking whether the target file can be created, if not, reporting errors and terminating operation.
The C language code analysis module is used for reading the content of the C language file and judging the sentence type of each C language sentence; the type of statement is an element constituting a C language code, for example: macro definitions, global variables, constructs, function declarations and definitions.
The execution module is used for acquiring the transplanting rule of the sentence type from the rule module according to the sentence type analyzed by the C language code analysis module; checking whether the content to be matched in each migration rule is matched with the content of the current C language code sentence, if so, executing the operation of the migration rule, and outputting the executed content to the target file. This operation is repeated until the C language code file ends. And finally, storing the content of the target file, and ending the system operation.
A cross-platform transplanting method for C language source codes adopts the cross-platform transplanting system for C language source codes, and comprises the following steps:
when the system operates, firstly, a user is required to specify a rule file, a C language file and a transplanted target file path;
then, the checking module checks whether the C language file and the rule file appointed by the user exist or not, if not, the error is reported, and the transplanting system terminates operation; then testing whether the target file can be created, if the target file fails, reporting errors, and terminating the operation of the transplanting system;
the rule module analyzes the rule file, analyzes the rule in the rule file from the text description into a data structure, namely rule class object data, stores the rule class object data into a rule Map according to the classification of an execution object, and provides the rule of a specified statement type (namely the execution object) for other modules;
the C language code analysis module reads the content of the C language file and executes the following operations on each row of content: judging whether the current content is an annotation or not, and outputting the annotation to a target file if the current content is the annotation; if the annotation is not the annotation, firstly eliminating the annotation in the content, and then judging the type of the annotation; if the type cannot be judged, carrying out statement type analysis by combining the next row of content of the C language file until the statement type is determined; transmitting the statement and statement type information to an execution module;
the execution module acquires the transplanting rules of the statement type from the rule module according to the statement type, screens and reserves the transplanting rules with the actual execution times smaller than the execution times (the time attribute of the rules), and then executes the following operation on each rule:
checking whether a matching template in the rule matches statement content, if so, executing the operation of the rule, outputting the executed content to a target file, and recording the actual execution times of the rule plus one; if not, not processing;
after the execution module processes the whole C language file, the execution module saves the target file, and the operation of the transplanting system is finished.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (8)

1. A C language source code cross-platform transplanting system is characterized by comprising a rule module, a verification module, a C language code analysis module and an execution module;
the rule module is used for analyzing the rule file, converting the transplanting rule in the rule file into a data structure, and storing the data structure into a computer memory for subsequent use;
the checking module is used for checking whether the C language code file and the rule file exist or not, if not, reporting errors and terminating operation; checking whether the target file can be created or not, if not, reporting errors and terminating operation;
the C language code analysis module is used for reading the content of the C language file and judging the sentence type of each C language sentence;
the execution module is used for acquiring the transplanting rule of the sentence type from the rule module according to the sentence type analyzed by the C language code analysis module; checking whether the content to be matched in each migration rule is matched with the content of the current C language code sentence, if so, executing the operation of the migration rule, and outputting the executed content to the target file.
2. A C-language source code cross-platform migration system according to claim 1, wherein a plurality of migration rules are defined in the rule file, the migration rules describing the content to be matched and the operations to be performed thereon.
3. The C-language source code cross-platform migration system of claim 1, wherein the rule module defines rule types including add-class rules, annotate-class rules, replace-class rules, and delete-class rules.
4. The C-language source code cross-platform migration system of claim 1, wherein the new added class rules include operation type, added content, added location, number of executions information.
5. The C-language source code cross-platform migration system of claim 1, wherein the annotation class rules comprise operation type, execution object, execution times, matching templates, matching type information.
6. The C-language source code cross-platform migration system of claim 1, wherein the substitution class rules comprise operation type, execution object, execution times, matching templates, target template information.
7. The C-language source code cross-platform migration system of claim 1, wherein the deletion class rules include operation type, execution object, execution times, matching template, matching type information.
8. A cross-platform migration method for C-language source codes, which adopts the cross-platform migration system for C-language source codes according to any one of claims 1-7, and is characterized by comprising the following steps:
when the system operates, firstly, a user is required to specify a rule file, a C language file and a transplanted target file path;
then, the checking module checks whether the C language file and the rule file appointed by the user exist or not, if not, the error is reported, and the transplanting system terminates operation; then testing whether the target file can be created, if the target file fails, reporting errors, and terminating the operation of the transplanting system;
the rule module analyzes the rule file, analyzes the rule from the text description into a data structure, namely rule class object data, stores the rule class object data into a rule Map according to the classification of an execution object, and provides rules of specified sentence types for other modules;
the C language code analysis module reads the content of the C language file and executes the following operations on each row of content: judging whether the current content is an annotation or not, and outputting the annotation to a target file if the current content is the annotation; if the annotation is not the annotation, firstly eliminating the annotation in the content, and then judging the type of the annotation; if the type cannot be judged, carrying out statement type analysis by combining the next row of content of the C language file until the statement type is determined; transmitting the statement and statement type information to an execution module;
the execution module acquires the transplanting rules of the sentence type from the rule module according to the sentence type, screens and reserves the transplanting rules with the actual execution times smaller than the execution times, and then executes the following operations on each rule:
checking whether a matching template in the rule matches statement content, if so, executing the operation of the rule, outputting the executed content to a target file, and recording the actual execution times of the rule plus one; if not, not processing;
after the execution module processes the whole C language file, the execution module saves the target file, and the operation of the transplanting system is finished.
CN202310511500.0A 2023-05-08 2023-05-08 Cross-platform transplanting system and transplanting method for C language source codes Pending CN116594687A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310511500.0A CN116594687A (en) 2023-05-08 2023-05-08 Cross-platform transplanting system and transplanting method for C language source codes

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310511500.0A CN116594687A (en) 2023-05-08 2023-05-08 Cross-platform transplanting system and transplanting method for C language source codes

Publications (1)

Publication Number Publication Date
CN116594687A true CN116594687A (en) 2023-08-15

Family

ID=87600033

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310511500.0A Pending CN116594687A (en) 2023-05-08 2023-05-08 Cross-platform transplanting system and transplanting method for C language source codes

Country Status (1)

Country Link
CN (1) CN116594687A (en)

Similar Documents

Publication Publication Date Title
US11797298B2 (en) Automating identification of code snippets for library suggestion models
US11354225B2 (en) Automating identification of test cases for library suggestion models
US11494181B2 (en) Automating generation of library suggestion engine models
CN110457260A (en) Document handling method, device, equipment and computer readable storage medium
WO2006136055A1 (en) A text data mining method
CN111124380A (en) Front-end code generation method
CN116088846A (en) Processing method, related device and equipment for continuous integrated code format
CN111026604B (en) Log file analysis method and device
CN109885821B (en) Article writing method and device based on artificial intelligence and computer storage medium
CN116594687A (en) Cross-platform transplanting system and transplanting method for C language source codes
CN115543832A (en) Software code standard detection method, system, equipment and storage medium
CN112230904A (en) Code generation method and device based on interface document, storage medium and server
CN116501303B (en) Automatic API code generation method and device
CN114385271B (en) Command execution system based on plug-in
US20230251857A1 (en) Development support device, non-transitory computer-readable medium, and development support method
Fraternali et al. Almost rerere: An approach for automating conflict resolution from similar resolved conflicts
Ji et al. Structure preserving transformations for practical model-based systems engineering
CN110765020B (en) Test case generation method based on domain knowledge
CN114610320A (en) LLVM-based variable type information repairing and comparing method and system
US20240004620A1 (en) Automated generation of web applications based on wireframe metadata generated from user requirements
KR100656559B1 (en) Program Automatic Generating Tools
CN117217214A (en) C# grammar tree generation method, application, system, storage medium and electronic equipment
CN117687620A (en) File generation method and device, terminal equipment and computer readable storage medium
CN117234587A (en) Mobile test script intention recognition method based on combination of image understanding and code analysis
CN114020751A (en) Big data platform management system, method, equipment and storage medium

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