CN110134380B - Code generation method and device based on template engine and electronic equipment - Google Patents

Code generation method and device based on template engine and electronic equipment Download PDF

Info

Publication number
CN110134380B
CN110134380B CN201910250600.6A CN201910250600A CN110134380B CN 110134380 B CN110134380 B CN 110134380B CN 201910250600 A CN201910250600 A CN 201910250600A CN 110134380 B CN110134380 B CN 110134380B
Authority
CN
China
Prior art keywords
code file
source
source code
data source
data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910250600.6A
Other languages
Chinese (zh)
Other versions
CN110134380A (en
Inventor
马东辉
张建华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing CHJ Automotive Information Technology Co Ltd
Original Assignee
Beijing CHJ Automotive Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing CHJ Automotive Information Technology Co Ltd filed Critical Beijing CHJ Automotive Information Technology Co Ltd
Priority to CN201910250600.6A priority Critical patent/CN110134380B/en
Publication of CN110134380A publication Critical patent/CN110134380A/en
Application granted granted Critical
Publication of CN110134380B publication Critical patent/CN110134380B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

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

Abstract

The embodiment of the disclosure provides a code generation method and device based on a template engine and electronic equipment. The method is applied to electronic equipment, wherein the electronic equipment stores a plurality of source code files associated with a template engine, and the source code files correspond to a plurality of data sources; the method comprises the following steps: receiving a code generation request; wherein the code generation request is associated with a first data source; determining a second data source on which the first data source depends according to a preset dependency relationship; the dependency relationship among a plurality of data sources is recorded in the preset dependency relationship; and generating a first target code file corresponding to the first source code file according to the first source code file corresponding to the first data source and the second source code file corresponding to the second data source. Compared with the prior art, the method and the device can effectively improve the generation efficiency of the code file and greatly shorten the time for generating the code file required by operators.

Description

Code generation method and device based on template engine and electronic equipment
Technical Field
The embodiment of the disclosure relates to the technical field of communication, in particular to a code generation method and device based on a template engine and electronic equipment.
Background
Currently, there are many template engines in the field of communication technology, and most template engines are capable of providing an ability to generate an object code file (which is a computer executable code file) from a source code file, in which the object code file generally needs to be written manually by an operator using the template engine, so that in the prior art, the generation efficiency of the object code file is very low, and particularly in the case that the number of object code files to be generated is very large, it takes a very long time to generate the required object code file.
Disclosure of Invention
In a first aspect, embodiments of the present disclosure provide a code generation method based on a template engine, applied to an electronic device, where the electronic device stores a plurality of source code files associated with the template engine, where the plurality of source code files correspond to a plurality of data sources;
the method comprises the following steps:
receiving a code generation request; wherein the code generation request is associated with a first data source;
determining a second data source on which the first data source depends according to a preset dependency relationship; wherein, the preset dependency relationship records the dependency relationship among the plurality of data sources;
And generating a first target code file corresponding to the first source code file according to the first source code file corresponding to the first data source and the second source code file corresponding to the second data source.
In some embodiments, the generating a first object code file corresponding to the first source code file according to a first source code file corresponding to the first data source and a second source code file corresponding to the second data source includes:
obtaining an intermediate code file corresponding to the second source code file according to the second source code file corresponding to the second data source;
resolving the obtained intermediate code file to obtain a first resolving result;
constructing according to the first source code file and the first analysis result to obtain a first construction code;
and obtaining a first target code file corresponding to the first source code file according to the first construction code.
In some embodiments, the obtaining, according to the first build code, a first object code file corresponding to the first source code file includes:
acquiring first processing instruction information corresponding to the first source code file;
And processing the first construction code according to the first processing instruction information to obtain a first target code file corresponding to the first source code file.
In some embodiments, the first processing instruction information includes at least one of:
information for indicating compression;
information for indicating injection of the hook code;
debug information.
In some embodiments, the obtaining, according to the second source code file corresponding to the second data source, an intermediate code file corresponding to the second source code file includes:
determining whether the second data source has a dependent third data source according to the preset dependency relationship;
if not, taking the second source code file as an intermediate code file corresponding to the second source code file;
if yes, obtaining an intermediate code file corresponding to the third source code file; resolving the obtained intermediate code file to obtain a second resolving result; constructing according to the second source code file and the second analysis result to obtain a second construction code; obtaining an intermediate code file corresponding to the second source code file according to the second construction code; wherein the third source code file corresponds to the third data source.
In some embodiments, the parsing the obtained intermediate code file to obtain a first parsing result includes:
determining file attributes of the obtained intermediate code file;
and calling a parser corresponding to the file attribute, and parsing the obtained intermediate code file to obtain a first parsing result.
In some embodiments, each data source records the file storage location of its corresponding source code file;
the generating a first target code file corresponding to the first source code file according to the first source code file corresponding to the first data source and the second source code file corresponding to the second data source includes:
obtaining a first source code file corresponding to the first data source according to a file storage position recorded in the first data source, and obtaining a second source code file corresponding to the second data source according to a file storage position recorded in the second data source;
and generating a first target code file corresponding to the first source code file according to the first source code file and the second source code file.
In a second aspect, embodiments of the present disclosure provide a code generating apparatus based on a template engine, applied to an electronic device, where the electronic device stores a plurality of source code files associated with the template engine, where the plurality of source code files correspond to a plurality of data sources;
The device comprises:
the receiving module is used for receiving the code generation request; wherein the code generation request is associated with a first data source;
the determining module is used for determining a second data source on which the first data source depends according to a preset dependency relationship; wherein, the preset dependency relationship records the dependency relationship among the plurality of data sources;
and the generating module is used for generating a first target code file corresponding to the first source code file according to the first source code file corresponding to the first data source and the second source code file corresponding to the second data source.
In some embodiments, the generating module includes:
the first obtaining submodule is used for obtaining an intermediate code file corresponding to the second source code file according to the second source code file corresponding to the second data source;
the analysis sub-module is used for analyzing the obtained intermediate code file to obtain a first analysis result;
the construction submodule is used for constructing according to the first source code file and the first analysis result to obtain a first construction code;
and the second obtaining submodule is used for obtaining a first target code file corresponding to the first source code file according to the first construction code.
In some embodiments, the second obtaining sub-module includes:
the first obtaining unit is used for obtaining first processing instruction information corresponding to the first source code file;
and the second obtaining unit is used for processing the first construction code according to the first processing instruction information so as to obtain a first target code file corresponding to the first source code file.
In some embodiments, the first processing instruction information includes at least one of:
information for indicating compression;
information for indicating injection of the hook code;
debug information.
In some embodiments, the first obtaining sub-module includes:
the first obtaining sub-module includes:
the first determining unit is used for determining whether the second data source has a dependent third data source according to the preset dependency relationship; if not, triggering a second determining unit; if yes, triggering a processing unit;
the second determining unit is configured to use the second source code file as an intermediate code file corresponding to the second source code file;
the processing unit is used for obtaining an intermediate code file corresponding to the third source code file; resolving the obtained intermediate code file to obtain a second resolving result; constructing according to the second source code file and the second analysis result to obtain a second construction code; obtaining an intermediate code file corresponding to the second source code file according to the second construction code; wherein the third source code file corresponds to the third data source.
In some embodiments, the parsing sub-module includes:
a third determination unit configured to determine a file attribute of the obtained intermediate code file;
and the analysis unit is used for calling the analyzer corresponding to the file attribute and analyzing the obtained intermediate code file to obtain a first analysis result.
In some embodiments, each data source records the file storage location of its corresponding source code file;
the generating module comprises:
a third obtaining sub-module, configured to obtain a first source code file corresponding to the first data source according to a file storage location recorded in the first data source, and obtain a second source code file corresponding to the second data source according to a file storage location recorded in the second data source;
and the generating sub-module is used for generating a first target code file corresponding to the first source code file according to the first source code file and the second source code file.
In a third aspect, embodiments of the present disclosure provide an electronic device comprising a processor, a memory, a computer program stored on the memory and executable on the processor, which when executed by the processor implements the steps of the template engine based code generation method described above.
In a fourth aspect, embodiments of the present disclosure provide a computer readable storage medium having a computer program stored thereon, which when executed by a processor, implements the steps of the template engine-based code generation method described above.
Drawings
FIG. 1 is a flow chart of a template engine based code generation method provided by an embodiment of the present disclosure;
FIG. 2 is a schematic diagram of generating an object code file in an embodiment of the present disclosure;
FIG. 3 is a specific dependency graph;
FIG. 4 is another specific dependency graph;
FIG. 5 is a block diagram of a code generation apparatus based on a template engine provided by an embodiment of the present disclosure;
fig. 6 is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure.
Detailed Description
The following description of the technical solutions in the embodiments of the present disclosure will be made clearly and completely with reference to the accompanying drawings in the embodiments of the present disclosure, and it is apparent that the described embodiments are some embodiments of the present disclosure, but not all embodiments. All other embodiments, which are derived by a person of ordinary skill in the art from the embodiments in the disclosure without creative efforts, are within the protection scope of the present disclosure.
A description will be first given of a template engine-based code generation method provided by an embodiment of the present disclosure.
It should be noted that, the code generating method based on the template engine provided by the embodiment of the present disclosure is applied to an electronic device, where the electronic device stores a plurality of source code files associated with the template engine, and the plurality of source code files correspond to a plurality of data sources.
It should be noted that the "plurality" referred to in the embodiments of the present disclosure each refer to at least two; the electronic device may be a server and the source code file may also be referred to as a template file.
In general, a template engine may provide a variety of grammars, such as loop grammar, judgment grammar, modular grammar, reference grammar, etc., and a plurality of source code files associated with the template engine may refer to: a plurality of source code files using the syntax provided by the template engine, and the syntax used by different source code files is different.
In addition, the plurality of source code files and the plurality of data sources may have a one-to-one correspondence. For any data source, it may be obtained by abstracting the corresponding source code file, which may define the file suffix, file format, file storage location (which may also be referred to as a resource path) of the corresponding source code file. In this way, the data source can mask details between source code files of different types and different grammars to form a base model that can characterize the source code files.
Referring to fig. 1, a flowchart of a template engine-based code generation method provided by an embodiment of the present disclosure is shown. As shown in fig. 1, the method comprises the steps of:
step 101, receiving a code generation request; wherein the code generation request is associated with a first data source.
Here, the first data source may be any data source of a plurality of data sources, and "first" in the first data source does not constitute any limitation on the first data source.
Specifically, a plurality of options corresponding to the plurality of data sources one to one may be displayed on an interface of the electronic device, and an operator may perform a touch operation or a mouse click operation on the option corresponding to the first data source to initiate a code generation request associated with the first data source.
Step 102, determining a second data source on which the first data source depends according to a preset dependency relationship; the preset dependency relationship records the dependency relationship among a plurality of data sources.
In general, there are dependencies (may also be referred to as call relationships) between the plurality of source code files, and since the preset dependencies record the dependencies between the plurality of data sources and the plurality of source code files correspond to the plurality of data sources, the preset dependencies can be considered to characterize the dependencies between the plurality of source code files.
In specific implementation, a large number of files written based on the template engine may be obtained in advance, for example, a plurality of files in the file set in fig. 2 are obtained, and then file scanning is performed to obtain a preset dependency relationship in which a dependency relationship between a plurality of data sources is recorded, for example, to obtain a data source dependency relationship graph in fig. 2. As can be seen from FIG. 2, the data sources can be mutually dependent and referred to each other to form a directed acyclic graph, each data source is a node in the directed acyclic graph, and the dependency relationship among all the data sources can be obtained by traversing the directed acyclic graph.
The number of second data sources on which the first data source depends may be one, two, three or more, and is not listed here.
And step 103, generating a first target code file corresponding to the first source code file according to the first source code file corresponding to the first data source and the second source code file corresponding to the second data source.
It should be noted that, the specific implementation manner of step 103 is various, and for the sake of layout clarity, the following description will be given by way of example.
For the generated first object code file, the first object code file can be directly compiled into a JavaScript (which is an transliteration script language) type component, and the first object code file can be rendered and executed on a server side or a browser side so as to remarkably improve the reusability of codes.
In an embodiment of the disclosure, after receiving a code generation request associated with a first data source and determining a second data source on which the first data source depends according to a preset dependency relationship, an electronic device may generate a first target code file corresponding to the first source code file according to a first source code file corresponding to the first data source and a second source code file corresponding to the second data source. Therefore, compared with the situation that an operator needs to write codes manually by using a template engine in the prior art, the embodiment of the invention can effectively improve the generation efficiency of the code files and greatly shorten the time for generating the code files required by the operator.
In some embodiments, each data source records the file storage location of its corresponding source code file;
generating a first target code file corresponding to the first source code file according to the first source code file corresponding to the first data source and the second source code file corresponding to the second data source, including:
According to the file storage position recorded in the first data source, a first source code file corresponding to the first data source is obtained, and according to the file storage position recorded in the second data source, a second source code file corresponding to the second data source is obtained;
and generating a first target code file corresponding to the first source code file according to the first source code file and the second source code file.
In the embodiment of the disclosure, since each data source records a corresponding file storage location, based on the data source, the electronic device can very conveniently acquire the corresponding source code file so as to generate the corresponding target code file according to the corresponding source code file.
It should be noted that the corresponding file storage location may not be recorded in each data source, and it is also possible that the electronic device may record the correspondence between the data source and the file storage location of the corresponding source code file in other storage areas.
In some embodiments, generating a first object code file corresponding to the first source code file according to a first source code file corresponding to the first data source and a second source code file corresponding to the second data source includes:
obtaining an intermediate code file corresponding to the second source code file according to the second source code file corresponding to the second data source;
Resolving the obtained intermediate code file to obtain a first resolving result;
constructing according to the first source code file and the first analysis result to obtain a first construction code;
and obtaining a first target code file corresponding to the first source code file according to the first construction code.
It should be noted that, according to the first build code, specific implementation forms of the first object code file corresponding to the first source code file are various, and are described below by way of example.
In one implementation, according to the first build code, obtaining a first object code file corresponding to the first source code file includes:
acquiring first processing instruction information corresponding to a first source code file;
and processing the first build code according to the first processing instruction information to obtain a first target code file corresponding to the first source code file.
Specifically, processing instruction information of a corresponding source code file can be recorded in each data source, so that the electronic equipment can obtain the processing instruction information from the first data source, and the obtained processing instruction information is used as first processing instruction information; or, the correspondence between the active code file and the processing instruction information may be stored in advance, and the electronic device may obtain, according to the correspondence stored in advance, first processing instruction information corresponding to the first source code file.
Here, the first processing instruction information may include at least one of:
information for indicating compression;
information for indicating injection of the hook code;
debug information.
Assuming that the first processing instruction information only includes information for indicating compression, after the first build code is obtained, the electronic device may compress the first build code, and the compressed first build code may be used as a first object code file corresponding to the first source code. Assuming that the first processing instruction information only includes information for indicating injection of the hook code, after obtaining the first build code, the electronic device may inject the hook code into the first build code, and the first build code after injection of the hook code may be used as a first object code file corresponding to the first source code.
In the implementation form, the first construction code is processed based on the first processing instruction information, and the finally obtained first target code file can be flexibly controlled, so that the first target code file can better meet the actual requirements.
In another implementation form, according to the first build code, obtaining a first object code file corresponding to the first source code file includes:
And taking the first build code as a first target code file corresponding to the first source code file.
In the implementation form, the first build code can be directly used as the first target code file, so that the target code file required by the user can be obtained very conveniently.
In the embodiment of the disclosure, an intermediate code file corresponding to a second source code file may be obtained first, then a first analysis result obtained by analyzing the intermediate code file is obtained, and then a first construction code may be obtained by constructing according to the first source code file and the first analysis result, where the first construction code may embody a dependency relationship between the first source code file and the second source code file. And then, according to the first construction code, obtaining a first target code file required by the user. Therefore, the process of generating the first target code file by the first source code file and the second source code file does not need manual writing by operators, so that the generation efficiency of the code file can be better ensured.
In some embodiments, resolving the obtained intermediate code file to obtain a first resolving result includes:
determining file attributes of the obtained intermediate code file;
And calling a parser corresponding to the file attribute, and parsing the obtained intermediate code file to obtain a first parsing result.
Here, the file attribute of the intermediate code file may include a language used by the intermediate code file. Specifically, in the case where the language used for the intermediate code file is a cascading style sheet (Cascading Style Sheets, CSS), the CSS parser may be called to parse the intermediate code file; in the case where the language used for the intermediate code file is hypertext markup language (HyperText Markup Language, HTML), an HTML parser may be invoked to parse the intermediate code file; in the case that the language used by the intermediate code file is JavaScript, a JavaScript parser may be invoked to parse the intermediate code file.
It can be seen that in the embodiment of the disclosure, the corresponding parser may be invoked to parse the intermediate code file according to the file attribute, so as to ensure the reliability of the parsing result.
In some embodiments, obtaining an intermediate code file corresponding to the second source code file according to the second source code file corresponding to the second data source includes:
determining whether the second data source has a dependent third data source according to a preset dependency relationship;
If not, taking the second source code file as an intermediate code file corresponding to the second source code file;
if yes, obtaining an intermediate code file corresponding to the third source code file; resolving the obtained intermediate code file to obtain a second resolving result; constructing according to the second source code file and the second analysis result to obtain a second construction code; obtaining an intermediate code file corresponding to the second source code file according to the second construction code; wherein the third source code file corresponds to a third data source.
Here, in the case where the second data source has a dependent third data source, the number of third data sources may be one, two, three or more, which are not listed here.
Here, the file attribute of the intermediate code file corresponding to the third source code file may be determined, and the parser corresponding to the file attribute may be called to parse the intermediate code file corresponding to the third source code file. In addition, the obtaining process of the intermediate code file corresponding to the third source code file may refer to the obtaining process of the intermediate code file corresponding to the second source code file, which is not described herein.
For ease of understanding, the following detailed description of the specific implementation of the embodiments of the present disclosure is given in terms of a specific example.
Assuming that the template engine is associated with six source code files Y1 through Y6, the data source corresponding to Y1 may be Y1, the data source corresponding to Y2 may be Y2, the data source corresponding to Y3 may be Y3, the data source corresponding to Y4 may be Y4, the data source corresponding to Y5 may be Y5, and the data source corresponding to Y6 may be Y6.
The electronic device receives the code generation request associated with y1 (where y1 corresponds to the first data source above), based on the preset dependency relationship, as shown in fig. 3, the electronic device may determine that y1 depends on y2 and y3 (where y2 and y3 correspond to the second data source above), y2 depends on y4 and y5 (where y4 and y5 correspond to the third data source above), y3 depends on y6 (where y6 corresponds to the third data source above), and y4, y5, and y6 do not depend on other data sources. Next, the electronic device may generate an intermediate code file corresponding to Y2 and an intermediate code file corresponding to Y3, and then generate an object code file corresponding to Y1 according to the intermediate code file corresponding to Y2 and the intermediate code file corresponding to Y3.
Since Y4, Y5, and Y6 are independent of other data sources, Y4 may be the intermediate code file corresponding to Y4, Y5 may be the intermediate code file corresponding to Y5, and Y6 may be the intermediate code file corresponding to Y6.
Specifically, in order to generate the intermediate code file corresponding to Y2, the electronic device may first parse Y4 and Y5 respectively to obtain a parsed result of Y4 and a parsed result of Y5. Then, the electronic device may construct according to the analysis results of Y2 and Y4 and the analysis result of Y5 to obtain a construction code, and use the obtained construction code as an intermediate code file corresponding to Y2.
Similarly, to generate the intermediate code file corresponding to Y3, the electronic device may first parse Y6 to obtain a parsed result of Y6. Then, the electronic device may perform construction according to the analysis result of Y3 and Y6 to obtain a construction code, and use the obtained construction code as an intermediate code file corresponding to Y3.
After the intermediate code file corresponding to Y2 and the intermediate code file corresponding to Y3 are obtained, the two intermediate code files may be parsed respectively to obtain two parsing results. Then, the electronic device may perform construction according to Y1 and the two obtained analysis results to obtain a construction code, and use the obtained construction code as an object code file corresponding to Y1.
It should be noted that, on the basis of fig. 3, if Y4 also depends on other data sources (for example, Y7 and Y8), then the intermediate code file corresponding to Y4 needs to be generated according to the other data sources, and the specific generating process only needs to refer to the process of generating the intermediate code file corresponding to Y3 based on Y6, which is not described herein.
It can be seen that, in the embodiments of the present disclosure, based on the preset dependency relationship, the intermediate code files may be generated layer by layer according to the dependency hierarchy between the data sources until the target code files required by the operator are obtained.
It should be noted that, as can be seen from fig. 2 and the above embodiments, the template engine in the embodiments of the present disclosure can provide three capabilities, namely, single template file compiling, template file relationship management, and template generation configuration management, so as to solve the problem of mutual reference between template files in different grammars and the problem of complex management and maintenance of template files with large data volume. In addition, the template engine can be compatible with other template engines, and the other template engines can be used as a data source of the template engine, so that the calling among different types of templates is realized, and the existing resources can be reused more easily.
In summary, in the embodiment of the disclosure, by adopting the abstraction from the source code file to the data source and generating the preset dependency relationship, the generation of the code file required by the operator can be realized very conveniently, the template engine is easier to expand, and a flexible mechanism is provided for the subsequent upgrading and expansion of the template engine; in addition, by processing instruction information, generation and optimization of code files can be flexibly controlled.
Embodiments of the present disclosure provide a template engine-based code generation apparatus described below.
Referring to fig. 5, a block diagram of a template engine-based code generation apparatus 500 provided by an embodiment of the present disclosure is shown. As shown in fig. 5, the code generating apparatus 500 based on the template engine is applied to an electronic device, and the electronic device stores a plurality of source code files associated with the template engine, wherein the plurality of source code files correspond to a plurality of data sources;
the template engine-based code generation apparatus 500 includes:
a receiving module 501, configured to receive a code generation request; wherein the code generation request is associated with a first data source;
a determining module 502, configured to determine, according to a preset dependency relationship, a second data source on which the first data source depends; the dependency relationship among a plurality of data sources is recorded in the preset dependency relationship;
the generating module 503 is configured to generate a first object code file corresponding to the first source code file according to the first source code file corresponding to the first data source and the second source code file corresponding to the second data source.
In some embodiments, the generating module 503 includes:
the first obtaining submodule is used for obtaining an intermediate code file corresponding to the second source code file according to the second source code file corresponding to the second data source;
The analysis sub-module is used for analyzing the obtained intermediate code file to obtain a first analysis result;
the construction sub-module is used for constructing according to the first source code file and the first analysis result to obtain a first construction code;
and the second obtaining submodule is used for obtaining a first target code file corresponding to the first source code file according to the first construction code.
In some embodiments, the second obtaining sub-module comprises:
the first obtaining unit is used for obtaining first processing instruction information corresponding to the first source code file;
and the second obtaining unit is used for processing the first construction code according to the first processing instruction information so as to obtain a first target code file corresponding to the first source code file.
In some embodiments, the first processing instruction information includes at least one of:
information for indicating compression;
information for indicating injection of the hook code;
debug information.
In some embodiments, the first obtaining sub-module comprises:
the first determining unit is used for determining whether the second data source has a dependent third data source according to a preset dependency relationship; if not, triggering a second determining unit; if yes, triggering a processing unit;
The second determining unit is used for taking the second source code file as an intermediate code file corresponding to the second source code file;
the processing unit is used for obtaining an intermediate code file corresponding to the third source code file; resolving the obtained intermediate code file to obtain a second resolving result; constructing according to the second source code file and the second analysis result to obtain a second construction code; obtaining an intermediate code file corresponding to the second source code file according to the second construction code; wherein the third source code file corresponds to a third data source.
In some embodiments, the parsing sub-module includes:
a third determination unit configured to determine a file attribute of the obtained intermediate code file;
and the analysis unit is used for calling the analyzer corresponding to the file attribute and analyzing the obtained intermediate code file to obtain a first analysis result.
In some embodiments, each data source records the file storage location of its corresponding source code file;
the generating module 503 includes:
the third obtaining submodule is used for obtaining a first source code file corresponding to the first data source according to the file storage position recorded in the first data source and obtaining a second source code file corresponding to the second data source according to the file storage position recorded in the second data source;
And the generating sub-module is used for generating a first target code file corresponding to the first source code file according to the first source code file and the second source code file.
Therefore, compared with the situation that an operator needs to write codes manually by using a template engine in the prior art, the embodiment of the invention can effectively improve the generation efficiency of the code files and greatly shorten the time for generating the code files required by the operator.
An electronic device provided by an embodiment of the present disclosure is described below.
Referring to fig. 6, a schematic structural diagram of an electronic device 600 provided by an embodiment of the present disclosure is shown. As shown in fig. 6, the electronic device 600 includes: a processor 601, a transceiver 602, a memory 603, a user interface 604 and a bus interface.
The electronic device 600 stores a plurality of source code files associated with a template engine, the plurality of source code files corresponding to a plurality of data sources; a processor 601 for reading the program in the memory 603, performing the following procedures:
Receiving a code generation request; wherein the code generation request is associated with a first data source;
determining a second data source on which the first data source depends according to a preset dependency relationship; the dependency relationship among a plurality of data sources is recorded in the preset dependency relationship;
and generating a first target code file corresponding to the first source code file according to the first source code file corresponding to the first data source and the second source code file corresponding to the second data source.
In fig. 6, a bus architecture may comprise any number of interconnected buses and bridges, with various circuits of the one or more processors, represented in particular by processor 601, and the memory, represented in memory 603. The bus architecture may also link together various other circuits such as peripheral devices, voltage regulators, power management circuits, etc., which are well known in the art and, therefore, will not be described further herein. The bus interface provides an interface. The transceiver 602 may be a number of elements, i.e., including a transmitter and a receiver, providing a means for communicating with various other apparatus over a transmission medium. The user interface 604 may also be an interface capable of interfacing with an inscribed desired device for a different user device, including but not limited to a keypad, display, speaker, microphone, joystick, etc.
The processor 601 is responsible for managing the bus architecture and general processing, and the memory 603 may store data used by the processor 601 in performing operations.
In some embodiments, the processor 601 is specifically configured to:
obtaining an intermediate code file corresponding to the second source code file according to the second source code file corresponding to the second data source;
resolving the obtained intermediate code file to obtain a first resolving result;
constructing according to the first source code file and the first analysis result to obtain a first construction code;
and obtaining a first target code file corresponding to the first source code file according to the first construction code.
In some embodiments, the processor 601 is specifically configured to:
acquiring first processing instruction information corresponding to a first source code file;
and processing the first build code according to the first processing instruction information to obtain a first target code file corresponding to the first source code file.
In some embodiments, the first processing instruction information includes at least one of:
information for indicating compression;
information for indicating injection of the hook code;
debug information.
In some embodiments, the processor 601 is specifically configured to:
Determining whether the second data source has a dependent third data source according to a preset dependency relationship;
if not, taking the second source code file as an intermediate code file corresponding to the second source code file;
if yes, obtaining an intermediate code file corresponding to the third source code file; resolving the obtained intermediate code file to obtain a second resolving result; constructing according to the second source code file and the second analysis result to obtain a second construction code; obtaining an intermediate code file corresponding to the second source code file according to the second construction code; wherein the third source code file corresponds to a third data source.
In some embodiments, the processor 601 is specifically configured to:
determining file attributes of the obtained intermediate code file;
and calling a parser corresponding to the file attribute, and parsing the obtained intermediate code file to obtain a first parsing result.
In some embodiments, each data source records the file storage location of its corresponding source code file;
the processor 601 is specifically configured to:
according to the file storage position recorded in the first data source, a first source code file corresponding to the first data source is obtained, and according to the file storage position recorded in the second data source, a second source code file corresponding to the second data source is obtained;
And generating a first target code file corresponding to the first source code file according to the first source code file and the second source code file.
Therefore, compared with the situation that an operator needs to write codes manually by using a template engine in the prior art, the embodiment of the disclosure can effectively improve the generation efficiency of the code files and greatly shorten the time for generating the code files required by the operator.
The embodiments of the present disclosure further provide an electronic device, including a processor 601, a memory 603, and a computer program stored in the memory 603 and capable of running on the processor 601, where the computer program when executed by the processor 701 implements each process in the foregoing embodiments of the code generation method based on the template engine and can achieve the same technical effect, and for avoiding repetition, a description is omitted herein.
Embodiments of the present disclosure further provide a computer readable storage medium, on which a computer program is stored, where the computer program, when executed by the processor 601, implements each process in the foregoing embodiments of the code generation method based on a template engine, and the same technical effects can be achieved, and in order to avoid repetition, will not be repeated herein. Wherein the computer readable storage medium is selected from Read-Only Memory (ROM), random access Memory (Random Access Memory, RAM), magnetic disk or optical disk.
The foregoing is merely specific embodiments of the disclosure, but the protection scope of the disclosure is not limited thereto, and any person skilled in the art can easily think about changes or substitutions within the technical scope of the disclosure, and it is intended to cover the scope of the disclosure. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.

Claims (14)

1. The code generation method based on the template engine is characterized by being applied to electronic equipment, wherein the electronic equipment stores a plurality of source code files associated with the template engine, and the source code files correspond to a plurality of data sources;
the method comprises the following steps:
receiving a code generation request; wherein the code generation request is associated with a first data source;
determining a second data source on which the first data source depends according to a preset dependency relationship; wherein, the preset dependency relationship records the dependency relationship among the plurality of data sources; the data sources form a directed acyclic graph through mutual dependence and mutual reference, each data source is a node in the directed acyclic graph, and the dependence relationship among all the data sources can be obtained through traversing the directed acyclic graph;
Generating a first target code file corresponding to the first source code file according to the first source code file corresponding to the first data source and the second source code file corresponding to the second data source; any data source is obtained by abstracting the corresponding source code files, and the data source can shield details among source code files with different types and different grammars so as to form a basic model capable of representing the source code files;
the generating a first target code file corresponding to the first source code file according to the first source code file corresponding to the first data source and the second source code file corresponding to the second data source includes:
obtaining an intermediate code file corresponding to the second source code file according to the second source code file corresponding to the second data source;
resolving the obtained intermediate code file to obtain a first resolving result;
constructing according to the first source code file and the first analysis result to obtain a first construction code, wherein the first construction code can embody the dependency relationship between the first source code file and the second source code file;
and obtaining a first target code file corresponding to the first source code file according to the first construction code.
2. The method according to claim 1, wherein obtaining a first object code file corresponding to the first source code file according to the first build code includes:
acquiring first processing instruction information corresponding to the first source code file;
and processing the first construction code according to the first processing instruction information to obtain a first target code file corresponding to the first source code file.
3. The method of claim 2, wherein the first processing instruction information includes at least one of:
information for indicating compression;
information for indicating injection of the hook code;
debug information.
4. The method according to claim 1, wherein the obtaining, according to the second source code file corresponding to the second data source, an intermediate code file corresponding to the second source code file includes:
determining whether the second data source has a dependent third data source according to the preset dependency relationship;
if not, taking the second source code file as an intermediate code file corresponding to the second source code file;
if yes, obtaining an intermediate code file corresponding to the third source code file; resolving the obtained intermediate code file to obtain a second resolving result; constructing according to the second source code file and the second analysis result to obtain a second construction code; obtaining an intermediate code file corresponding to the second source code file according to the second construction code; wherein the third source code file corresponds to the third data source.
5. The method according to claim 1, wherein parsing the obtained intermediate code file to obtain a first parsing result includes:
determining file attributes of the obtained intermediate code file;
and calling a parser corresponding to the file attribute, and parsing the obtained intermediate code file to obtain a first parsing result.
6. The method of claim 1, wherein each data source has recorded therein a file storage location of its corresponding source code file;
the generating a first target code file corresponding to the first source code file according to the first source code file corresponding to the first data source and the second source code file corresponding to the second data source includes:
obtaining a first source code file corresponding to the first data source according to a file storage position recorded in the first data source, and obtaining a second source code file corresponding to the second data source according to a file storage position recorded in the second data source;
and generating a first target code file corresponding to the first source code file according to the first source code file and the second source code file.
7. A code generating device based on a template engine, which is characterized by being applied to electronic equipment, wherein the electronic equipment stores a plurality of source code files associated with the template engine, and the source code files correspond to a plurality of data sources;
the device comprises:
the receiving module is used for receiving the code generation request; wherein the code generation request is associated with a first data source;
the determining module is used for determining a second data source on which the first data source depends according to a preset dependency relationship; wherein, the preset dependency relationship records the dependency relationship among the plurality of data sources; the data sources form a directed acyclic graph through mutual dependence and mutual reference, each data source is a node in the directed acyclic graph, and the dependence relationship among all the data sources can be obtained through traversing the directed acyclic graph;
the generation module is used for generating a first target code file corresponding to the first source code file according to the first source code file corresponding to the first data source and the second source code file corresponding to the second data source; any data source is obtained by abstracting the corresponding source code files, and the data source can shield details among source code files with different types and different grammars so as to form a basic model capable of representing the source code files;
The generating module comprises:
the first obtaining submodule is used for obtaining an intermediate code file corresponding to the second source code file according to the second source code file corresponding to the second data source;
the analysis sub-module is used for analyzing the obtained intermediate code file to obtain a first analysis result;
the construction sub-module is used for constructing according to the first source code file and the first analysis result to obtain a first construction code, and the first construction code can embody the dependency relationship between the first source code file and the second source code file;
and the second obtaining submodule is used for obtaining a first target code file corresponding to the first source code file according to the first construction code.
8. The apparatus of claim 7, wherein the second obtaining sub-module comprises:
the first obtaining unit is used for obtaining first processing instruction information corresponding to the first source code file;
and the second obtaining unit is used for processing the first construction code according to the first processing instruction information so as to obtain a first target code file corresponding to the first source code file.
9. The apparatus of claim 8, wherein the first processing instruction information includes at least one of:
Information for indicating compression;
information for indicating injection of the hook code;
debug information.
10. The apparatus of claim 7, wherein the first obtaining sub-module comprises:
the first determining unit is used for determining whether the second data source has a dependent third data source according to the preset dependency relationship; if not, triggering a second determining unit; if yes, triggering a processing unit;
the second determining unit is configured to use the second source code file as an intermediate code file corresponding to the second source code file;
the processing unit is used for obtaining an intermediate code file corresponding to the third source code file; resolving the obtained intermediate code file to obtain a second resolving result; constructing according to the second source code file and the second analysis result to obtain a second construction code; obtaining an intermediate code file corresponding to the second source code file according to the second construction code; wherein the third source code file corresponds to the third data source.
11. The apparatus of claim 7, wherein the parsing sub-module comprises:
A third determination unit configured to determine a file attribute of the obtained intermediate code file;
and the analysis unit is used for calling the analyzer corresponding to the file attribute and analyzing the obtained intermediate code file to obtain a first analysis result.
12. The apparatus of claim 7, wherein each data source has recorded therein a file storage location for its corresponding source code file;
the generating module comprises:
a third obtaining sub-module, configured to obtain a first source code file corresponding to the first data source according to a file storage location recorded in the first data source, and obtain a second source code file corresponding to the second data source according to a file storage location recorded in the second data source;
and the generating sub-module is used for generating a first target code file corresponding to the first source code file according to the first source code file and the second source code file.
13. An electronic device comprising a processor, a memory, a computer program stored on the memory and executable on the processor, which when executed by the processor, implements the steps of the template engine based code generation method of any one of claims 1 to 6.
14. A computer-readable storage medium, on which a computer program is stored, which computer program, when being executed by a processor, implements the steps of the template engine based code generation method of any of claims 1 to 6.
CN201910250600.6A 2019-03-29 2019-03-29 Code generation method and device based on template engine and electronic equipment Active CN110134380B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910250600.6A CN110134380B (en) 2019-03-29 2019-03-29 Code generation method and device based on template engine and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910250600.6A CN110134380B (en) 2019-03-29 2019-03-29 Code generation method and device based on template engine and electronic equipment

Publications (2)

Publication Number Publication Date
CN110134380A CN110134380A (en) 2019-08-16
CN110134380B true CN110134380B (en) 2023-11-10

Family

ID=67568824

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910250600.6A Active CN110134380B (en) 2019-03-29 2019-03-29 Code generation method and device based on template engine and electronic equipment

Country Status (1)

Country Link
CN (1) CN110134380B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110555178B (en) * 2019-08-28 2020-07-21 贝壳找房(北京)科技有限公司 Data proxy method and device
CN112860248B (en) * 2019-11-27 2023-12-05 中盈优创资讯科技有限公司 Source code generation method and device
CN112328256B (en) * 2020-11-19 2023-04-25 四川创智联恒科技有限公司 Method for automatically generating source code of structural body analyzer

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101470602A (en) * 2007-12-25 2009-07-01 新奥特(北京)视频技术有限公司 Software development method depending on relational database
CN104679511A (en) * 2015-02-10 2015-06-03 北京系统工程研究所 Method for generating MapReduce codes based on MDE (Model-Driven Engineering) model transformation

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101841515B (en) * 2009-03-19 2014-01-08 北京理工大学 Target variable protocol data unit codec code automatic generation implementation method
US9330263B2 (en) * 2014-05-27 2016-05-03 Intuit Inc. Method and apparatus for automating the building of threat models for the public cloud
CN108279879B (en) * 2018-01-25 2018-12-18 北京卓越智软科技有限公司 Applied software development method towards engine

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101470602A (en) * 2007-12-25 2009-07-01 新奥特(北京)视频技术有限公司 Software development method depending on relational database
CN104679511A (en) * 2015-02-10 2015-06-03 北京系统工程研究所 Method for generating MapReduce codes based on MDE (Model-Driven Engineering) model transformation

Also Published As

Publication number Publication date
CN110134380A (en) 2019-08-16

Similar Documents

Publication Publication Date Title
KR100995199B1 (en) Reflection-based processing of input parameters for commands
Bryant et al. Challenges and directions in formalizing the semantics of modeling languages
CN100492290C (en) Method for acquiring and converting the state of component in the time of operation during software dynamic evolvement
CN110134380B (en) Code generation method and device based on template engine and electronic equipment
EP1723561A1 (en) Method, data processing device, computer program product and arrangement for processing electronic data
US10666744B2 (en) Managing discovery and selection of service interface specifications
CN114691464A (en) Interface testing method, computer equipment and computer readable storage medium
CN112083919A (en) YAML template-based target service code generation method and device
CN111176629A (en) Application development method and device
CN115904989A (en) Interface testing method, device, equipment and readable storage medium
CN113238739A (en) Plug-in development and data acquisition method, device, electronic equipment and medium
CN112631563A (en) System development method and device based on framework, computer equipment and storage medium
Cirilo et al. Model driven RichUbi: a model driven process for building rich interfaces of context-sensitive ubiquitous applications
CN115599361A (en) Software development method, device, equipment and medium
CN112667202B (en) Software design method and device combining MDA and BPMN
US8943476B2 (en) System and method to in-line script dependencies
US20040153871A1 (en) Automatic analysis of the properties of a system based on runtime logs
CN115080416A (en) Test method based on service code and related equipment thereof
CN110737431B (en) Software development method, development platform, terminal device and storage medium
CN112394920A (en) Application software development method, platform and electronic equipment
CN111880775A (en) Multi-module layered architecture implementation method and device, electronic equipment and storage medium
Baker et al. Early UML model testing using TTCN-3 and the UML testing profile
CN113986322B (en) Method, device and storage medium for dynamically modifying page codes
CN115061900A (en) Method, system, equipment and medium for locally debugging offline package
CN117687634A (en) Service compiling method and device and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant