CN116820565A - Source code processing method, device, electronic equipment and medium - Google Patents

Source code processing method, device, electronic equipment and medium Download PDF

Info

Publication number
CN116820565A
CN116820565A CN202310771311.7A CN202310771311A CN116820565A CN 116820565 A CN116820565 A CN 116820565A CN 202310771311 A CN202310771311 A CN 202310771311A CN 116820565 A CN116820565 A CN 116820565A
Authority
CN
China
Prior art keywords
processed
language
function
target
source code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310771311.7A
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.)
CCB Finetech Co Ltd
Original Assignee
CCB Finetech 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 CCB Finetech Co Ltd filed Critical CCB Finetech Co Ltd
Priority to CN202310771311.7A priority Critical patent/CN116820565A/en
Publication of CN116820565A publication Critical patent/CN116820565A/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
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention provides a source code processing method, a source code processing device, electronic equipment and a source code processing medium, relates to the technical field of computers, and can be applied to the technical field of finance. The method comprises the following steps: acquiring a source code to be processed, wherein the source code to be processed comprises a C language program to be processed; determining to-be-processed information in a to-be-processed C language program, wherein the to-be-processed information comprises one or more of a to-be-processed C language character array, a to-be-processed function matched with a preset function and a to-be-processed C language data structure; processing the information to be processed to obtain a processed target result; and obtaining a target source code according to the target result, wherein the target source code comprises a target JAVA language program.

Description

Source code processing method, device, electronic equipment and medium
Technical Field
The present invention relates to the field of computer technology, and may be applied to the field of financial technology, and more particularly, to a source code processing method, apparatus, device, medium, and program product.
Background
With the updating of technology, the main development language of enterprises is gradually changed from the C language to the JAVA language. How to migrate a C program to a JAVA platform has become a problem to be solved.
For example, some old projects lack relevant documents with only active codes, and when these C source codes are transplanted to a JAVA platform, service requirements are reversely carded from the source codes, and then JAVA language design and development are performed based on the carded service requirements. The transplanting mode is extremely easy to generate understanding deviation, so that JAVA implementation is not matched with C implementation, and meanwhile, source code comparison and walking are difficult. Therefore, the method of reversely carding the service requirement from the source code and then designing and developing the JAVA language based on the carded service requirement is difficult to ensure the quality, and further the method can lead to long transplanting period and poor delivery result.
Disclosure of Invention
In view of the above problems, the present invention provides a source code processing method, apparatus, device, medium, and program product, by acquiring a source code to be processed, the source code to be processed including a C language program to be processed; determining information to be processed in a C language program to be processed; processing the information to be processed to obtain a processed target result; and obtaining target source codes according to the target result, wherein the target source codes comprise target JAVA language programs. The transplanting work of the C language program does not need to re-comb the service requirement and redesign, so that the transplanting difficulty is greatly reduced, the service scene is fully restored, the source code conversion quality is improved, and the source code transplanting effect is ensured.
According to a first aspect of the present invention, there is provided a source code processing method, comprising: acquiring a source code to be processed, wherein the source code to be processed comprises a C language program to be processed; determining to-be-processed information in the to-be-processed C language program, wherein the to-be-processed information comprises one or more of to-be-processed C language character arrays, to-be-processed functions matched with preset functions and to-be-processed C language data structures; processing the information to be processed to obtain a processed target result; and obtaining target source codes according to the target result, wherein the target source codes comprise target JAVA language programs.
According to the embodiment of the invention, under the condition that the information to be processed comprises the C language character array to be processed, the C language character array to be processed is processed, and the processed target result comprises: acquiring a preset JAVA language byte array; and replacing the C language character array by using the JAVA language byte array to obtain a processed first target result.
According to an embodiment of the present invention, when it is determined that the information to be processed includes a function to be processed, the function to be processed includes at least one of a C-language copy character string function, a C-language judgment character string length function, a C-language blank removal character function, a C-language comparison character string function, and a C-language print function, and the processing is performed on the function to be processed, so that a processed target result includes: acquiring a preset JAVA language function matched with the function to be processed; and replacing the function to be processed by the JAVA language function to obtain a processed second target result.
According to the embodiment of the invention, under the condition that the information to be processed comprises a C language data structure to be processed, the C language data structure to be processed is processed, and the processed target result comprises: acquiring a preset instance of JAVA language class; replacing the C language character array by using the instance of the JAVA language class to obtain a processed third target result; and configuring the third target result as a public attribute.
According to an embodiment of the present invention, the method further comprises: and according to the target result, realizing the target source code.
According to an embodiment of the present invention, the implementation of the target source code according to the target result includes: and under the condition that the preset JAVA language function comprises a JAVA language judging character string length function, traversing the byte array in the target result, and determining the character string length.
According to an embodiment of the present invention, the implementation of the target source code according to the target result includes: under the condition that the preset JAVA language function comprises a JAVA language blank character removing function, positioning the positions of non-blank characters before and after the byte array according to the byte array in the target result; and performing blank character removal processing according to the position of the non-blank character to obtain a processed byte array.
According to an embodiment of the present invention, the implementation of the target source code according to the target result includes: and under the condition that the preset JAVA language function comprises a JAVA language comparison character string function, comparing the value of each byte of the two byte arrays in the target result according to the return value meaning of the C language comparison character string function, and determining a comparison result.
According to an embodiment of the present invention, the implementation of the target source code according to the target result includes: under the condition that the preset JAVA language function comprises a JAVA language formatted output function, defining a result after the temporary variable record is formatted in response to receiving a target parameter; wherein the target parameters include a format string parameter and a variable parameter; initializing an engine of a character string writing operation, and initializing a downloading file stream based on the engine of the character string writing operation; writing a formatting result obtained according to the target parameter into an engine of the character string writing-out operation by utilizing the downloaded file stream; storing the formatting result into a temporary variable by using an engine of the character string writing operation; and returning the temporary variable.
A second aspect of the present invention provides a source code processing apparatus comprising: the acquisition module is used for acquiring a source code to be processed, wherein the source code to be processed comprises a C language program to be processed; the determining module is used for determining to-be-processed information in the to-be-processed C language program, wherein the to-be-processed information comprises one or more of to-be-processed C language character arrays, to-be-processed functions matched with preset functions and to-be-processed C language data structures; the processing module is used for processing the information to be processed to obtain a processed target result; and the obtaining module is used for obtaining target source codes according to the target result, wherein the target source codes comprise target JAVA language programs.
A third aspect of the present invention provides an electronic device comprising: one or more processors; and a memory for storing one or more programs, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the source code processing method described above.
A fourth aspect of the present invention also provides a computer readable storage medium having stored thereon executable instructions which, when executed by a processor, cause the processor to perform the above-described source code processing method.
The fifth aspect of the present invention also provides a computer program product comprising a computer program which, when executed by a processor, implements the source code processing method described above.
The source code processing method provided by the embodiment can obtain the source code to be processed, wherein the source code to be processed comprises the C language program to be processed; determining information to be processed in a C language program to be processed; processing the information to be processed to obtain a processed target result; and obtaining target source codes according to the target result, wherein the target source codes comprise target JAVA language programs. The transplanting work of the C language program does not need to re-comb the service requirement and redesign, so that the transplanting difficulty is greatly reduced, the service scene is fully restored, the source code conversion quality is improved, and the source code transplanting effect is ensured.
Drawings
The foregoing and other objects, features and advantages of the invention will be apparent from the following description of embodiments of the invention with reference to the accompanying drawings, in which:
FIG. 1 schematically illustrates an application scenario diagram of a source code processing method, apparatus, device, medium and program product according to an embodiment of the invention;
FIG. 2 schematically illustrates a flow chart of a source code processing method according to an embodiment of the invention;
FIG. 3 schematically illustrates a flow chart of a source code processing method according to another embodiment of the invention;
FIG. 4 schematically shows a block diagram of a source code processing apparatus according to an embodiment of the present invention; and
fig. 5 schematically shows a block diagram of an electronic device adapted to implement a source code processing method according to an embodiment of the invention.
Detailed Description
Hereinafter, embodiments of the present invention will be described with reference to the accompanying drawings. It should be understood that the description is only illustrative and is not intended to limit the scope of the invention. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the invention. It may be evident, however, that one or more embodiments may be practiced without these specific details. In addition, in the following description, descriptions of well-known structures and techniques are omitted so as not to unnecessarily obscure the present invention.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. The terms "comprises," "comprising," and/or the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It should be noted that the terms used herein should be construed to have meanings consistent with the context of the present specification and should not be construed in an idealized or overly formal manner.
Where expressions like at least one of "A, B and C, etc. are used, the expressions should generally be interpreted in accordance with the meaning as commonly understood by those skilled in the art (e.g.," a system having at least one of A, B and C "shall include, but not be limited to, a system having a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).
The embodiment of the invention provides a source code processing method and a source code processing device, which are used for acquiring a source code to be processed, wherein the source code to be processed comprises a C language program to be processed; determining to-be-processed information in a to-be-processed C language program, wherein the to-be-processed information comprises one or more of a to-be-processed C language character array, a to-be-processed function matched with a preset function and a to-be-processed C language data structure; processing the information to be processed to obtain a processed target result; and obtaining a target source code according to the target result, wherein the target source code comprises a target JAVA language program.
Fig. 1 schematically illustrates an application scenario diagram of a source code processing method, apparatus, device, medium and program product according to an embodiment of the present invention.
As shown in fig. 1, an application scenario 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used as a medium to provide communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
The user may interact with the server 105 via the network 104 using the terminal devices 101, 102, 103 to receive or send messages or the like. Various communication client applications, such as shopping class applications, web browser applications, search class applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only) may be installed on the terminal devices 101, 102, 103.
The terminal devices 101, 102, 103 may be a variety of electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 105 may be a server providing various services, such as a background management server (by way of example only) providing support for websites browsed by users using the terminal devices 101, 102, 103. The background management server may analyze and process the received data such as the user request, and feed back the processing result (e.g., the web page, information, or data obtained or generated according to the user request) to the terminal device.
It should be noted that, the source code processing method provided by the embodiment of the present invention may be generally executed by the server 105. Accordingly, the source code processing apparatus provided in the embodiments of the present invention may be generally disposed in the server 105. The source code processing method provided by the embodiment of the present invention may also be performed by a server or a server cluster that is different from the server 105 and is capable of communicating with the terminal devices 101, 102, 103 and/or the server 105. Accordingly, the source code processing apparatus provided by the embodiment of the present invention may also be provided in a server or a server cluster, which is different from the server 105 and is capable of communicating with the terminal devices 101, 102, 103 and/or the server 105.
It should be understood that the number of terminal devices, networks and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The source code processing method of the disclosed embodiment will be described in detail below with reference to fig. 2 based on the scenario described in fig. 1.
Fig. 2 schematically shows a flow chart of a source code processing method according to an embodiment of the invention.
As shown in fig. 2, this embodiment includes operations S210 to S240, and the source code processing method may be performed by a server.
In the technical scheme of the invention, the processes of data acquisition, collection, storage, use, processing, transmission, provision, disclosure, application and the like all conform to the regulations of related laws and regulations, necessary security measures are adopted, and the public order harmony is not violated.
In operation S210, a source code to be processed is acquired, the source code to be processed including a C language program to be processed.
In operation S220, the information to be processed in the C language program to be processed is determined, where the information to be processed includes one or more of an array of C language characters to be processed, a function to be processed matching a preset function, and a C language data structure to be processed.
In operation S230, the information to be processed is processed to obtain a processed target result.
In operation S240, a target source code including a target JAVA language program is obtained according to the target result.
It can be understood that there is a certain difference between the grammar of the C language and the JAVA language, for example, the C language uses a character array to store character string data, and performs operations such as comparison, assignment, and the like based on the character array. And the JAVA language uses String type to store the character strings, and performs comparison and assignment operation based on String.
When the source code is transplanted (C language program to JAVA language program), if the service requirement is fully mastered, the service requirement can be directly reproduced by using JAVA language, and the C source code provides reference value. However, some old projects often have lost the relevant documents only with active codes, so that the business requirements cannot be fully mastered. Similar to the above situation, if the JAVA language is designed and developed through reverse carding service requirements, understanding deviation is very easy to occur, so that JAVA implementation is not matched with C implementation.
Because the application is generally a database-based business system, the C source code is basically the conventional use of the C language when the business needs are realized. The inventor finds that when C source codes are transplanted into JAVA language, the main difference is concentrated on the storage and processing of character string data, and then the calling of partial functions and the conversion of data structures are carried out.
Based on the difference between the C language and the JAVA language, in order to improve the conversion quality of source codes and reduce the migration difficulty, the JAVA language program can be used for realizing the storage of character strings of the C language program and the processing of C language functions, so that the use habit of the JAVA language is changed, and the JAVA language program obtained by processing the C language program can be realized on a JAVA platform.
And processing and converting the C language character string data, the function and the data structure to obtain the corresponding JAVA language. Further, after the source code migration is realized, a corresponding JAVA language program is obtained, and a specific realization method is configured for better realizing the JAVA language program on a JAVA platform. Specifically, for example, migration processing including C language character arrays, and implementation of corresponding JAVA language programs; for example, migration processing of C language functions and implementation of corresponding JAVA language programs; such as migration processing of C language data structures, and implementation of corresponding JAVA language programs. The C language function may include a C language copy string function, a C language judgment string length function, a C language blanking string function, a C language comparison string function, a C language print function, and the like, and various types of C language functions are not limited thereto.
It can be understood that the C language program to be processed in this embodiment is directed to character string data, functions, and data structures having differences between the C language and the JAVA language. Therefore, the C language program to be processed may include a C language character array, a C language function to be processed, a C language data structure, and the like, and the information to be processed may be set according to the requirement.
For example, a preset function may be set for a function to be processed in the information to be processed, and the function to be processed may be obtained by matching with a matching result of the preset function. If the function is consistent with the preset function, determining the function as the C language function to be processed.
It will be appreciated that for the information to be processed, further processing of the source code is required in order to be able to be implemented on a JAVA platform, with the processed result being the target source code, i.e. the JAVA language program. For example, a first target result is obtained by processing the C language character array to be processed; obtaining a second target result by processing the function to be processed; and obtaining a third target result by processing the C language data structure to be processed.
And obtaining target source code (JAVA language program) according to one or more of the first target result, the second target result and the third target result. For example, the target source code may include a target result or a combination of at least two target results.
The source code processing method provided by the embodiment can obtain the source code to be processed, wherein the source code to be processed comprises the C language program to be processed; determining information to be processed in a C language program to be processed; processing the information to be processed to obtain a processed target result; and obtaining target source codes according to the target result, wherein the target source codes comprise target JAVA language programs. The transplanting work of the C language program does not need to re-comb the service requirement and redesign, so that the transplanting difficulty is greatly reduced, the service scene is fully restored, the source code conversion quality is improved, and the source code transplanting effect is ensured.
Based on the above embodiment, for different information to be processed, in order to better understand how the disclosure processes the information to be processed, a processed target result is obtained. Further illustrated below in connection with the examples, but the present disclosure is not limited to the examples below.
For example, in the case that the to-be-processed information includes the to-be-processed C-language character array, processing the to-be-processed C-language character array to obtain the processed target result includes: acquiring a preset JAVA language byte array; and replacing the C language character array with the JAVA language byte array to obtain a processed first target result.
It will be appreciated that although JAVA provides String types to store strings, because the C language stores strings in character arrays (char), the String-related functions of the C language are all character array based, and that a JAVA language byte array may be used in place of the C language character array. If the C language states a string "char aString [11]", the JAVA language byte array simulation C states a string "byte [ ] aString=new byte [10]", which has a length of 10.
For example, in the case that it is determined that the information to be processed includes a function to be processed, the function to be processed includes at least one of a C-language copy character string function, a C-language judgment character string length function, a C-language blanking character function, a C-language comparison character string function, and a C-language printing function, the function to be processed is processed, and the processed target result includes: acquiring a preset JAVA language function matched with a function to be processed; and replacing the function to be processed by using the JAVA language function to obtain a processed second target result.
For example, for the C language copy string function (memcpy), a string copy (memcpy) library function call in the C program may be migrated as a JAVA language system. Such as C call "memcpy (dest, src, length)", instead of JAVA call: system. Arraymy (src, 0, dest,0, length).
For example, a string length function (strlen) is determined for the C language. The (strlen) library function call in the C program is transplanted into a common class static method call. Such as C call "strlen (aString)"; JAVA calls "Bytes, strlen (aString)".
For example, a blanked character function (trim) for the C language. Transplanting the library function call in the C program into a common class static method call. E.g., C calls "trim (aString)"; JAVA calls "Bytes, trim (aString)".
For example, a string function (memcmp) is compared for the C language. And transplanting the library function call in the C program (memcmp) into a common class static method call. C calls "memcmp (aString, bString, length)"; JAVA calls "Bytes, memcmp (aString, b String, length).
For example, a print function (printf) for the C language. And transplanting the formatted character string (printf, fprint, sprint and the like) library function call in the C program into a public class static method call. E.g. C calls "printf (format, param1, param 2)"; JAVA calls "Bytes, printf (format, param1, param 2).
For example, in the case that the to-be-processed information includes the to-be-processed C-language data structure, processing the to-be-processed C-language data structure to obtain the processed target result includes: acquiring a preset instance of JAVA language class; replacing the C language character array by using the instance of the JAVA language class to obtain a processed third target result; and configuring the third target result as a public attribute.
For example, for C language data structures (structs). In the database interaction scenario, the C language uses a structure (struct) to enter query parameters or receive query results, while the JAVA language uses an instance of a class (class). JAVA classes typically declare fields as a private attribute and then provide the corresponding get and set methods for the database API reflection.
For example, the C language expression data structure:
struct TABLE1{
char field1[10];
}
JAVA language expression data structure:
examples of improved JAVA language classes:
it can be understood that the structure of the C language is realized by using the class, and the JAVA class is modified as described above, so that the requirement that the C language function needs a character array and the JAVA database API needs a character string type can be satisfied.
1. The field type relating to the string is declared as a byte array (byte [ ]) while the field is declared as a public attribute, not a private attribute. This allows direct access to this field for array operations of the C language function.
2. Providing corresponding get and set methods for the fields to meet the JAVA API requirement, wherein the get method return value type of the fields is character strings, and the specific implementation is that byte [ ] is converted into the character strings of JAVA by calling the construction function of String; the set method receives the character string as the parameter type, and the method is specifically realized by calling the getBytes () method of the character string parameter, converting the character string into a byte array and then storing the byte array.
When the JAVA language reads and writes the properties of an object, the object is required to provide get and set methods, and get/set is required to follow the following naming convention: 1. get method naming convention: if the attribute is of the boolean type, it is required to be named is+ attribute name (capitalization), and if the attribute is of the other type, it is named get+ attribute name (capitalization). For example, the get method of attribute field1 may be isField1 or getField1. 2. set method naming convention: set + attribute name (capital). For example, the set method of attribute field1 may be setField1.
After the pending C language program is converted into the object source code including the JAVA language program, the object source code needs to be implemented in the JAVA platform. Thus, the object source code is further processed to run on the JAVA platform. Fig. 3 schematically shows a flow chart of a source code processing method according to another embodiment of the invention, see fig. 3.
In operation S250, a target source code is implemented according to a target result.
For example, the implementation of a JAVA language byte array after processing the C language character array. The C language states a String "char aString [11]" of length 10 "states a character" String aString ", and the simulation C states a String" byte [ ] astring=new byte [10] ".
For example, the JAVA language copy string function after processing the C language copy string function is implemented. The C language copy string function (memcpy) is a standard library function that provides a function of copying a given string to a specified string by a specified length. Such as "memcpy (void), const void, size_t". The memcpy function "arraypy (Object src, int srcPos, object dest, int destPos length)" is replaced by the JAVA language system.
For example, implementing the JAVA language judgment string length function after the C language judgment string length function processing may include traversing the byte array in the target result to determine the string length if it is determined that the preset JAVA language function includes the JAVA language judgment string length function. If the C language judging character string length function (strlen) is a label database function, a function of "strlen (const char)", which calculates the given character string length, is provided, the C language judging character string length function is replaced by a static strlen method, and the implementation traverses the given byte array and locates to the byte value position equal to 0 to calculate the character string length.
Specifically, as 1. A static method strlen of a common class (such as class name Bytes) is created. 2. The method receives 1 character string array (byte array) parameter, the return value is integer, and the return value is the actual length of the character string array. 3. The method first determines that if the parameter is null, return length 0.4. Save array length to temporary variable. 5. The index starts from 0 and takes 1 as step length to increase the cycle, each cycle judges whether the character value of the index marked by the index of the character string array is 0, if so, the value of the temporary variable is modified to be the current index value, and the cycle is exited; the loop is also exited when incrementing to the array maximum index. 6. The value of the temporary variable is returned.
For example, implementing the JAVA language blank-removing function after the C language blank-removing function processing may include locating, according to the byte array in the target result, the positions of non-blank characters before and after the byte array in the case that it is determined that the preset JAVA language function includes the JAVA language blank-removing function; and performing blank character removal processing according to the positions of the non-blank characters to obtain a processed byte array. If the C language blank removing character function (trim) is not a label database function, providing the capability of removing the head and tail blank characters of the character string, replacing the C language blank removing character function by a static trim method, firstly positioning the positions of the blank characters before and after the byte array, and then calling the arraycopy function to construct a new byte array public static int trim (byte [ ] bytes) ", wherein the blank characters are removed.
Specifically, 1. Create a static method trim for a common class. 2. The method receives 1 character string array (byte array) parameter, the return value is integer, and the return value is the actual length of the character string array after the head and tail blank characters are removed. 3. The temporary variables head and tail are defined and used for recording positions with the head and the tail not being blank respectively, the initial value of the head is 0, and the initial value of the tail is the maximum index of the array. And 4, tail is decremented by 1 step, each cycle judges whether the character value of the subscript tail of the character string array is blank (the value of the blank character is one of 32, 9, 10, 11, 12 and 13), if the blank character is blank, the value is modified to be 0, and otherwise, the cycle is jumped out. And 5, the head is increased by 1 step, each cycle judges whether the character value of the index of the character string array, which is marked as the head, is a blank character (the value of the blank character is one of 32, 9, 10, 11, 12 and 13), if the blank character is blank, the value is modified to be 0, and otherwise, the cycle is jumped out. 6. And calling an arraycopy function, and copying the character strings from the head in the array to the position from 0 in the array. 7. The strlen method is called to return the length of the new array.
For example, implementing the JAVA language blanked character function after the C language comparison character string function processing may include determining a comparison result according to a return value meaning of the C language comparison character string function in the case that it is determined that the preset JAVA language function includes the JAVA language comparison character string function, comparing a value of each byte of the two byte arrays in the target result. For example, a C language comparison string function (memcmp) is a label database function, and provides a function of "memcmp (const void), which compares the size of a given string, a static memcmp method is used to replace the C language comparison string function, compare the value of each byte of two byte arrays, and return a comparison result" public static int memcmp (byte [ ] first, byte [ ] second, int length) ", according to the value meaning of the C function.
Specifically, 1. Create a static method memcmp of public class. 2. The method receives 3 parameters, wherein the first two parameters are character string arrays (byte arrays) which participate in comparison, the 3 rd parameter designates the number of bits for comparison, the return value is integer, the return value is equal to 0 and indicates that the two character string parameters are equal, the former character is smaller than the latter character string when the return value is smaller than 0, and the former character is larger than the latter character string when the return value is larger than 0. 3. And defining a temporary variable record comparison result, and initializing to 0.4. And taking the minimum value of the two array lengths and the 3 rd parameter as the actual comparison length to prevent the out-of-range access to the array. 5. The loop is incremented by 1 step from 0, each loop is decremented by the value of the index specified by the 2 nd array counter by the 1 st array, if the result of the subtraction is not 0, the result is returned, and the method is exited. 6. If the actual comparison length is equal to the 3 rd parameter, returning to 0 and exiting the method. 7. If the actual comparison length is less than the 2 nd array length, a value less than 0 is returned. 8. If the actual compare length is less than the 1 st array length, a value greater than 0 is returned.
For example, implementing the JAVA language formatted output function after the C language print function processing may include defining a result after the temporary variable record is formatted in response to receiving the target parameter in a case where it is determined that the preset JAVA language function includes the JAVA language formatted output function; wherein the target parameters include a format string parameter and a variable parameter; initializing an engine of a character string writing operation, and initializing a downloading file stream based on the engine of the character string writing operation; writing a formatting result obtained according to the target parameter into an engine of the character string writing-out operation by utilizing the downloaded file stream; storing the formatting result into a temporary variable by using an engine of the character string writing operation; and returning the temporary variable. For example, the C language print function (printf) is a label database function, and a formatted output function "printf (const char, …)" is provided, instead of the C language print function (printf) "public static String printf (String format, object … ars)" based on the printf method of the JAVA language PrintWriter class.
Specifically, 1. Create a static method printf of a public class. 2. The method receives 2 parameters, wherein the first parameter is a format character string, the 2 nd parameter is a variable parameter, the variable parameter is used for transmitting parameters to the format character string, the return value is a character string type, and the return value is a formatted character string. 3. Defining a result after the temporary variable record is formatted. 4. The StringWriter is initialized and the PrnterWriter is initialized based on this StringWriter. 5. And calling a printf method of the PrinterWriter, and transmitting the 2 parameters received in the step 2, wherein the printf writes the formatting result into the StringWriter. 6. And calling a toString method of the StringWriter, and storing the formatting result of the printf into a temporary variable. 7. Returning the temporary variable.
According to the source code processing method provided by the embodiment, the target source code can be realized according to the target result, so that the target source code fully restores the service scene of C in the JAVA platform.
Based on the source code processing method, the invention also provides a source code processing device. The device will be described in detail below in connection with fig. 4.
Fig. 4 schematically shows a block diagram of a source code processing apparatus according to an embodiment of the present invention.
As shown in fig. 4, the source code processing apparatus 400 of this embodiment includes an acquisition module 410, a determination module 420, a processing module 430, and an acquisition module 440.
An obtaining module 410, configured to obtain a source code to be processed, where the source code to be processed includes a C language program to be processed; a determining module 420, configured to determine to-be-processed information in the to-be-processed C language program, where the to-be-processed information includes one or more of an to-be-processed C language character array, a to-be-processed function matched with a preset function, and a to-be-processed C language data structure; the processing module 430 is configured to process the information to be processed to obtain a processed target result; and an obtaining module 440, configured to obtain a target source code according to the target result, where the target source code includes a target JAVA language program.
In some embodiments, the apparatus further comprises: and the implementation module is used for implementing the target source code according to the target result.
Any of the acquisition module 410, determination module 420, processing module 430, and acquisition module 440 may be combined in one module to be implemented, or any of the modules may be split into multiple modules, according to embodiments of the present invention. Alternatively, at least some of the functionality of one or more of the modules may be combined with at least some of the functionality of other modules and implemented in one module. At least one of the acquisition module 410, the determination module 420, the processing module 430, and the acquisition module 440 may be implemented at least in part as hardware circuitry, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or in hardware or firmware, such as any other reasonable way of integrating or packaging circuitry, or in any one of or a suitable combination of three of software, hardware, and firmware, in accordance with embodiments of the present invention. Alternatively, at least one of the acquisition module 410, the determination module 420, the processing module 430, and the acquisition module 440 may be at least partially implemented as computer program modules, which when executed, may perform the corresponding functions.
Fig. 5 schematically shows a block diagram of an electronic device adapted to implement a source code processing method according to an embodiment of the invention.
As shown in fig. 5, an electronic device 500 according to an embodiment of the present invention includes a processor 501 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. The processor 501 may include, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or an associated chipset and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), or the like. The processor 501 may also include on-board memory for caching purposes. The processor 501 may comprise a single processing unit or a plurality of processing units for performing different actions of the method flow according to an embodiment of the invention.
In the RAM 503, various programs and data required for the operation of the electronic apparatus 500 are stored. The processor 501, ROM502, and RAM 503 are connected to each other by a bus 504. The processor 501 performs various operations of the method flow according to an embodiment of the present invention by executing programs in the ROM502 and/or the RAM 503. Note that the program may be stored in one or more memories other than the ROM502 and the RAM 503. The processor 501 may also perform various operations of the method flow according to embodiments of the present invention by executing programs stored in the one or more memories.
According to an embodiment of the invention, the electronic device 500 may further comprise an input/output (I/O) interface 505, the input/output (I/O) interface 505 also being connected to the bus 504. The electronic device 500 may also include one or more of the following components connected to the I/O interface 505: an input section 506 including a keyboard, a mouse, and the like; an output portion 507 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker, and the like; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The drive 510 is also connected to the I/O interface 505 as needed. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as needed so that a computer program read therefrom is mounted into the storage section 508 as needed.
The present invention also provides a computer-readable storage medium that may be embodied in the apparatus/device/system described in the above embodiments; or may exist alone without being assembled into the apparatus/device/system. The computer-readable storage medium carries one or more programs which, when executed, implement methods in accordance with embodiments of the present invention.
According to embodiments of the present invention, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example, but is not limited to: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. For example, according to embodiments of the invention, the computer-readable storage medium may include ROM 502 and/or RAM 503 and/or one or more memories other than ROM 502 and RAM 503 described above.
Embodiments of the present invention also include a computer program product comprising a computer program containing program code for performing the method shown in the flowcharts. The program code means for causing a computer system to carry out the source code processing method provided by the embodiment of the present invention when the computer program product is run on the computer system.
The above-described functions defined in the system/apparatus of the embodiment of the present invention are performed when the computer program is executed by the processor 501. The systems, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the invention.
In one embodiment, the computer program may be based on a tangible storage medium such as an optical storage device, a magnetic storage device, or the like. In another embodiment, the computer program may also be transmitted, distributed, and downloaded and installed in the form of a signal on a network medium, and/or installed from a removable medium 511 via the communication portion 509. The computer program may include program code that may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 509, and/or installed from the removable media 511. The above-described functions defined in the system of the embodiment of the present invention are performed when the computer program is executed by the processor 501. The systems, devices, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the invention.
According to embodiments of the present invention, program code for carrying out computer programs provided by embodiments of the present invention may be written in any combination of one or more programming languages, and in particular, such computer programs may be implemented in high-level procedural and/or object-oriented programming languages, and/or in assembly/machine languages. Programming languages include, but are not limited to, such as Java, c++, python, "C" or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of remote computing devices, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., connected via the Internet using an Internet service provider).
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that the features recited in the various embodiments of the invention and/or in the claims may be combined in various combinations and/or combinations even if such combinations or combinations are not explicitly recited in the invention. In particular, the features recited in the various embodiments of the invention and/or in the claims can be combined in various combinations and/or combinations without departing from the spirit and teachings of the invention. All such combinations and/or combinations fall within the scope of the invention.
The embodiments of the present invention are described above. However, these examples are for illustrative purposes only and are not intended to limit the scope of the present invention. Although the embodiments are described above separately, this does not mean that the measures in the embodiments cannot be used advantageously in combination. The scope of the invention is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be made by those skilled in the art without departing from the scope of the invention, and such alternatives and modifications are intended to fall within the scope of the invention.

Claims (13)

1. A source code processing method, comprising:
acquiring a source code to be processed, wherein the source code to be processed comprises a C language program to be processed;
Determining to-be-processed information in the to-be-processed C language program, wherein the to-be-processed information comprises one or more of to-be-processed C language character arrays, to-be-processed functions matched with preset functions and to-be-processed C language data structures;
processing the information to be processed to obtain a processed target result; and
and obtaining target source codes according to the target result, wherein the target source codes comprise target JAVA language programs.
2. The method of claim 1, wherein, in a case where it is determined that the information to be processed includes an array of C-language characters to be processed, processing the array of C-language characters to be processed to obtain a processed target result includes:
acquiring a preset JAVA language byte array; and
and replacing the C language character array by using the JAVA language byte array to obtain a processed first target result.
3. The method of claim 1, wherein, in a case where the information to be processed is determined to include a function to be processed, the function to be processed includes at least one of a C-language copy string function, a C-language judge string length function, a C-language debut string function, a C-language compare string function, and a C-language print function, processing the function to be processed, and obtaining a processed target result includes:
Acquiring a preset JAVA language function matched with the function to be processed; and
and replacing the function to be processed by the JAVA language function to obtain a processed second target result.
4. The method of claim 1, wherein, in a case where it is determined that the information to be processed includes a C-language data structure to be processed, processing the C-language data structure to obtain a processed target result includes:
acquiring a preset instance of JAVA language class;
replacing the C language character array by using the instance of the JAVA language class to obtain a processed third target result; and
and configuring the third target result as a public attribute.
5. The method of any one of claims 1-4, further comprising:
and according to the target result, realizing the target source code.
6. The method of claim 5, wherein the implementing the target source code according to the target result comprises:
under the condition that the preset JAVA language function is determined to comprise a JAVA language judgment character string length function, traversing the byte array in the target result, and determining the character string length.
7. The method of claim 5, wherein the implementing the target source code according to the target result comprises:
Under the condition that the preset JAVA language function comprises a JAVA language blank character removing function, positioning the positions of non-blank characters before and after the byte array according to the byte array in the target result; and
and performing blank character removal processing according to the positions of the non-blank characters to obtain a processed byte array.
8. The method of claim 5, wherein the implementing the target source code according to the target result comprises:
under the condition that the preset JAVA language function comprises the JAVA language comparison character string function is determined, comparing the value of each byte of the two byte arrays in the target result according to the return value meaning of the C language comparison character string function, and determining a comparison result.
9. The method of claim 5, wherein the implementing the target source code according to the target result comprises:
under the condition that the preset JAVA language function comprises a JAVA language formatted output function is determined, a temporary variable record formatted result is defined in response to receiving the target parameter; wherein the target parameters include a format string parameter and a variable parameter;
initializing an engine of a character string writing operation, and initializing a downloading file stream based on the engine of the character string writing operation;
Writing a formatting result obtained according to the target parameter into an engine of the character string writing-out operation by utilizing the downloaded file stream;
storing the formatting result into a temporary variable by using an engine of the character string writing operation; and
returning the temporary variable.
10. A source code processing apparatus comprising:
the acquisition module is used for acquiring a source code to be processed, wherein the source code to be processed comprises a C language program to be processed;
the determining module is used for determining to-be-processed information in the to-be-processed C language program, wherein the to-be-processed information comprises one or more of to-be-processed C language character arrays, to-be-processed functions matched with preset functions and to-be-processed C language data structures;
the processing module is used for processing the information to be processed to obtain a processed target result; and
and the obtaining module is used for obtaining target source codes according to the target result, wherein the target source codes comprise target JAVA language programs.
11. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs,
wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method of any of claims 1-9.
12. A computer readable storage medium having stored thereon executable instructions which, when executed by a processor, cause the processor to perform the method according to any of claims 1 to 9.
13. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1 to 9.
CN202310771311.7A 2023-06-27 2023-06-27 Source code processing method, device, electronic equipment and medium Pending CN116820565A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310771311.7A CN116820565A (en) 2023-06-27 2023-06-27 Source code processing method, device, electronic equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310771311.7A CN116820565A (en) 2023-06-27 2023-06-27 Source code processing method, device, electronic equipment and medium

Publications (1)

Publication Number Publication Date
CN116820565A true CN116820565A (en) 2023-09-29

Family

ID=88117973

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310771311.7A Pending CN116820565A (en) 2023-06-27 2023-06-27 Source code processing method, device, electronic equipment and medium

Country Status (1)

Country Link
CN (1) CN116820565A (en)

Similar Documents

Publication Publication Date Title
US10481884B2 (en) Systems and methods for dynamically replacing code objects for code pushdown
US10866791B2 (en) Transforming non-Apex code to Apex code
US9009183B2 (en) Transformation of a system change set from machine-consumable form to a form that is readily consumable by a human
US20240045850A1 (en) Systems and methods for database orientation transformation
CN109726217B (en) Database operation method, device, equipment and storage medium
CN111949693A (en) Data processing device, data processing method, storage medium and electronic equipment
CN109299913B (en) Employee salary scheme generation method and device
CN111125064A (en) Method and device for generating database mode definition statement
CN113419789A (en) Method and device for generating data model script
CN113419740A (en) Program data stream analysis method and device, electronic device and readable storage medium
CN113238739A (en) Plug-in development and data acquisition method, device, electronic equipment and medium
CN112579151A (en) Method and device for generating model file
CN115408009A (en) Code file generation method, device, equipment and storage medium
CN113535565B (en) Interface use case generation method, device, equipment and medium
CN113050987B (en) Method and device for generating interface document, storage medium and electronic equipment
CN113760240B (en) Method and device for generating data model
CN115145652A (en) Method, device, equipment and medium for creating data processing task
CN116820565A (en) Source code processing method, device, electronic equipment and medium
CN114816361A (en) Method, device, equipment, medium and program product for generating splicing project
CN113656041A (en) Data processing method, device, equipment and storage medium
CN113762702A (en) Workflow deployment method, device, computer system and readable storage medium
CN115687815A (en) Page information display method, device, equipment and medium
CN116382703B (en) Software package generation method, code development method and device, electronic equipment and medium
CN111782183B (en) Method and device for judging component dependency, electronic device and medium
CN116820566A (en) Data processing method, device, electronic 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