Search

CN-116909544-B - Automatic code generation method based on SysML model

CN116909544BCN 116909544 BCN116909544 BCN 116909544BCN-116909544-B

Abstract

A method for automatically generating code based on SysML model includes carrying out multi-level model verification on established SysML model according to SysML specification to ensure that SysML model is legal and effective, carrying out conversion and analysis on SysML model according to established model content file and combining multiple views in model, carrying out component definition and management, constructing normalized code mapping template, carrying out automatic generation of hierarchical code and generating final target language code. The invention can uniformly cooperate MBSE and MDA methods, provides a specific means for realizing the SysML model, effectively reduces the model design development difficulty, improves the design development capability of the model SysML model in the MBSE method, and ensures the efficiency and quality of system model development realization.

Inventors

  • WANG TIANTIAN
  • YANG PEIHAO
  • JIN QINCHAO
  • WU XIANGHU
  • WANG YIPING
  • SU XIAOHONG
  • WANG KECHAO

Assignees

  • 哈尔滨工业大学

Dates

Publication Date
20260512
Application Date
20230721

Claims (8)

  1. 1. The automatic code generation method based on the SysML model is characterized by comprising the following steps of: Step one, performing multi-level model verification on the established SysML model according to the SysML specification to ensure that the SysML model is legal and effective; step two, converting and analyzing the SysML model according to the established model content file and combining various views of the model; the method comprises the following steps of carrying out component definition and management, wherein components in the step three refer to packaged, abstract, reusable and replaceable units which can be used in different software systems in the modeling process of a model system, and component units are directly used as granularity in the code generation process, and the specific steps of the step three are as follows: step three, defining components, namely defining the attribute of the components, interface information of the components, dependency relationship of the components, applicable positions, entering and exiting conditions and basic framework information required by the components, and generating component description items; step three, component management, namely inserting component description items into a component description file, establishing primitive symbols of the components in a system to support graphical modeling of a SysML model, and managing the self description information of the components and the generation information of target language codes corresponding to the components by the component management, wherein high-efficiency codes corresponding to the component modules are prepared in advance before the codes of the SysML model are automatically generated, and are directly combined and pasted in the code generation process; Step four, constructing a normalized code mapping template; and fifthly, automatically generating the layering codes to generate final target language codes.
  2. 2. The method of automatic code generation based on SysML model according to claim 1, wherein the model verification in the first step is based on seven views of a package graph, a module definition graph, an internal module graph, a parameter graph, a timing graph, an activity graph and a state machine graph in the SysML model, and the verification content includes model self-verification consistency and phase consistency.
  3. 3. The method for automatically generating a code based on a SysML model according to claim 1, wherein in the second step, the model content file comprises a SysML model modeling element content file and a SysML model view content file.
  4. 4. The automatic code generation method based on the SysML model according to claim 1, wherein the specific steps of the second step are as follows: Step two, performing hierarchical analysis on a SysML model structure diagram to obtain hierarchical structure relations among model modeling elements; Step two, performing SysML model activity diagram synchronization processing, and analyzing activity diagram nodes contained in the activity diagram and connection relations among the nodes; Step two, performing the process of the SysML model state machine diagram, analyzing the states of the modules represented by the state machine diagram, and performing possible conversion among the states when responding to the event; and step two, performing flow processing of a SysML model time sequence diagram, analyzing a message interaction sequence among all components of a module represented in the time sequence diagram, and how all components interact through operation calling and asynchronous signals.
  5. 5. The automatic code generation method based on the SysML model according to claim 1, wherein the specific manner of component definition comprises a combination of one or more of A1, A2 and A3, wherein, A1, designing a meta-model component by using MOF as a specification, wherein the component definition process directly takes an instance of a meta-model as a component or indirectly takes an instance of an extended meta-model stereotype as a component; A2, after the SysML model is established, configuring a specific modeling module contained in the defined component, wherein the component contains information of a selected module in the system and only generates a corresponding target language code of the SysML module in a contained range; A3, defining the components through a component warehouse, namely directly importing the components from the existing component warehouse for use, modifying the components based on the imported components, and defining the specific components required by the user, wherein the component warehouse is stored in the cloud or locally.
  6. 6. The automatic code generation method based on the SysML model according to claim 5, wherein the source of the generated information of the target language code corresponding to the component comprises: b1, if the component is defined by the established SysML model and the model has undergone the process of automatically generating target language codes, the component adopts the target language codes of the results of the previous generation process as pre-generated target language codes; B2, if the component is directly imported and used by the component warehouse, and the component warehouse marks the automatic generation information of the target language code accompanied by the component when imported, the information is used as the target language generation code of the component; And B3, except the two cases, the component management calls a code automatic generation method based on the SysML model, so that all components utilized in the established SysML model are guaranteed to contain target language code information, and the process of calling the code automatic generation is a recursive process until the solved model does not contain components except the solved model and without the generated target language code information, so that the predefined component target language code is obtained.
  7. 7. The automatic code generation method based on the SysML model according to claim 1, wherein the specific process of the normalized code mapping template construction in the fourth step is that firstly, according to the code specification standard related in the industry, the code specification in the industry is analyzed, and then, the mapping relation between the SysML model elements and the target language code elements is determined by combining the characteristics of the SysML model elements and the grammar rules of the target language, so as to construct a safe and efficient target language code mapping template.
  8. 8. The automatic code generation method based on the SysML model according to claim 1, wherein the input of the hierarchical code automatic generation stage in the fifth step comprises the steps of model conversion and analysis content, component information and code mapping template information, and the method comprises the following steps: Analyzing the nested hierarchical relationship of each model element in the SysML, deeply analyzing layer by layer, generating a data structure and a method or a function interface by using a code mapping template according to each view information of the SysML model, and forming a program overall frame code; step five, generating program unit codes, namely expanding and analyzing layer by layer according to the nested hierarchical relationship of the SysML model, and generating implementation codes of each function by utilizing a code mapping template according to the contents of calling sequence relationships among each view and each model element; And fifthly, generating codes in a fusion way, and generating target language codes by combining codes according to the component library description file, the program overall frame codes and the program unit codes.

Description

Automatic code generation method based on SysML model Technical Field The invention belongs to the technical field of computers, relates to an automatic code generation method, and in particular relates to an automatic target language code generation method based on a SysML model. Background Model-based system engineering (MBSE) is a formal way of applying modeling methodologies to support system requirements, design, analysis, verification, and validation activities that begin at a conceptual design stage, throughout the development process and subsequent lifecycle stages. In the MBSE method, the system model is the center of the design, and each decision made in the design is captured as a model element (or relationship between elements) that is located at a single location in the system model. The model with good form can be constructed and read, is the core of MBSE method, and in the process of constructing the model, each modeling language is a standardized medium for communication, and the defined rules can endow the elements and the relations of the model with clear meanings. The system modeling language (SysML) is a modeling language commonly used in MBSE methods to create models of system architecture, behavior, requirements, and constraints, and can perform many system and supersystem specification, analysis, design, and verification and validation tasks. The system supported by SysML may include hardware devices, software inputs, personnel, procedures, facilities, and other man-made and natural system elements. The system model is constructed by the SysML from four aspects of a structural model, a behavior model, a demand model and a parameter model, wherein the structural model emphasizes the hierarchy of the system and the interconnection relation between objects, the behavior model emphasizes the behaviors of the objects in the system, including the activities, interactions and states of the objects, the demand model emphasizes the retroactive relation between demands and the meeting relation of the design to the demands, and the parameter model emphasizes the constraint relation between the attributes of the system or the components. Model Driven Architecture (MDA), a software design method, is used to separate business logic from the underlying platform to improve portability, interoperability and reusability of software. The MDA is based on a model conversion technology, and abstract models (such as a calculation irrelevant model, a platform irrelevant model and a platform relevant model) with different layers are converted with each other, so that automatic development of software is realized. Based on the development process of MDA, business personnel firstly constructs a Calculation Independent Model (CIM) through analysis and modeling in the business field to describe the requirement, then converts the Calculation Independent Model (CIM) into a Platform Independent Model (PIM) by combining with related standard specifications, and based on the Platform Independent Model (PIM), different platform dependent models (PSM) can be constructed according to different implementation environments, and finally the platform dependent model (PSM) is converted into target codes to complete the development process. Model-based system engineering (MBSE) is closely related to Model Driven Architecture (MDA). MBSE and MDA both use modeling techniques, but MBSE focuses more on modeling at the system level, while MDA focuses more on modeling at the software level. MBSE and MDA may cooperate, for example, using MDA as a development method for a software subsystem in MBSE, or using MBSE as a method for software requirement analysis and architecture design in MDA. In particular, the process of generating the object code from the SysML language model to the MDA in the MBSE method is an important implementation mode for uniformly cooperating the MBSE method and the MDA method, and the characteristics of formalization, visualization, verifiability, reusability and the like of the model can be utilized, so that the efficiency and quality of designing, developing and realizing the system model are improved, and the dynamic modeling and control of a complex system are realized. Therefore, in the process of developing and implementing the model based on MBSE methods, a reliable and efficient automatic object code generating method based on the SysML model is needed, the workload of code developers is reduced, unnecessary ambiguity is avoided from being introduced in the development process, and the quality and efficiency of implementing the system model are ensured. Disclosure of Invention In order to solve the problems, the invention provides a code automatic generation method based on a SysML model. The method automatically generates the high-efficiency object code capable of accurately expressing the model information based on the SysML model constructed by a modeling person, the generated object code considers t