Automatically Code Generation 【自动代码生成】

本文探讨如何通过编程自动生成代码,优化软件结构与增强软件的可扩展性。介绍了使用jEdit进行代码生成的方法,并提供了ArtisticStyle作为源代码整理工具的详细说明。文章还涉及了代码自动生成在不同编程语言中的应用,以及如何通过编辑View.java来扩展jEdit的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

No matter you are a C programmer, C++ PG, or Java PG, you would like to generate some code automatically by program written by yourself. Here is some materials for this kind of task.

How to build the data structure for your code analyzing?

How to generate code?

How to format the generated codes?

How about your software architecture?

How about your software extensibility?

...

 

I implementation is to use jEdit and add myself java codes into jEdit to fill my requirement about programming, as code generating and so on.

You can download jEdit from http://www.jedit.org/index.php?page=download.

How to extend jEdit?

One method is to edit View.java as following.

 

 

 

 


 

http://astyle.sourceforge.net/

 

Artistic Style 1.24

A Free, Fast and Small Automatic Formatter
for C, C++, C#, and Java Source Code

 

 

Artistic Style is a source code indenter, formatter, and beautifier for the C, C++, C# and Java programming languages.

When indenting source code, we as programmers have a tendency to use both spaces and tab characters to create the wanted indentation. Moreover, some editors by default insert spaces instead of tabs when pressing the tab key, and other editors (Emacs for example) have the ability to "pretty up" lines by automatically setting up the white space before the code on the line, possibly inserting spaces in a code that up to now used only tabs for indentation.

Since the NUMBER of space characters showed on screen for each tab character in the source code changes between editors (unless the user sets up the number to his liking...), one of the standard problems programmers are facing when moving from one editor to another is that code containing both spaces and tabs that was up to now perfectly indented, suddenly becomes a mess to look at when changing to another editor. Even if you as a programmer take care to ONLY use spaces or tabs, looking at other people's source code can still be problematic.

To address this problem, Artistic Style was created - a filter written in C++ that automatically re-indents and re-formats C / C++ / C# / Java source files. It can be used from a command line, or it can be incorporated as classes in another C++ program.

Documentation

There is complete documentation for using Artistic Style. Most documentation is included in the distribution package.

News and Release Notes

Information on the changes in the current release. The News contains information on major changes and how they might affect the use of Artistic Style. The Release Notes contains a list of all changes made to the program. Information on old releases is also listed.  

Download

The latest release can be downloaded from the SourceForge file releases page. The green "Download Now" button will, in most cases, download the correct package for your platform. Otherwise you can select the appropriate package from the "Newest Files" list. The OpenVMS and Windows packages contain compiled binaries. Other platforms will need to compile the source code. Makefiles are included for the most popular compilers. Follow the install instructions for the appropriate platform as described in the "Install Information" documentation.

Subversion

The latest development files can be checked out from the Artistic Style repository using Subversion.

Install Information

Information on compiling and installing Artistic Style. The Windows and OpenVMS platforms come with a precompiled executable. Other platforms must compile the project. Follow the instructions for the appropriate platform (Linux, Mac, OpenVMS, or Windows).

License

Artistic Style may be used and distributed under version 3 the GNU Lesser General Public License (LGPL). The LGPL is a set of additional permissions added to version 3 of the GNU General Public License. You can use Artistic Style in free or commercial software without charge. Projects that use Artistic Style do not have to make the source code available. If Artistic Style itself is modified, however, the modified Artistic Style source code must be made available.

Scripts

This page contains scripts to support the Artistic Style program. They are in various script languages and work on different platforms. It includes scripts to clean the directories of backup files created by Artistic Style.

Links

There are several applications that use Artistic Style as contributed software. It is either embedded in the application or called as a command line program. The applications include Graphical User Interfaces to view the effect of formatting on the source code, development environments for various platforms, and other software. 

Developer Information

Artistic Style has compile options for creating a shared library (DLL) or static library for use with a Graphical User Interface (GUI). With the Java Development Kit (JDK) installed it can be compiled as a Java Native Interface (JNI) and called from a Java program. The Developer Information documents the calling procedure and has example programs for C++, Java, and C#.

Bug Reports, Change Requests, Notification

Bug reports and change requests should be submitted to the bug tracker page. It is best to log in to SourceForge before submitting a report so you can be contacted if necessary. Note that code copied and pasted into the bug report will not be indented after the data is submitted. You must indicate the indentation when you submit the request (e.g. replace leading spaces with periods).

New releases are announced through an astyle-announce mailing list. You will receive notification of new releases and important repository commits. No SourceForge user account is needed, but registered site users can subscribe using their SourceForge mail alias. (Mail aliases take the form: username@users.sourceforge.net). The sign-up page can also be accessed from the user support page. There are other ways to subscribe on the file releases page that use an RSS feed. You can use them if you want.

To contact the project by email use the address jimp03@email.com.

Maintainers

Artistic Style is maintained and updated by Jim Pattee. The original author was Tal Davidson, Israel.

Acknowledgments

Thanks to Jim Watson, Fred Shwartz, W. Nathaniel Mills III, Danny Deschenes, Andre Houde, Richard Bullington, Paul-Michael Agapow, Daryn Adler, Dieter Bayer, Sam Cooler, Jim Duff, Emilio Guijarro, Jens Krinke, Eran Ifrah, Travis Robinson, Max Horn, Ettl Martin, Mario Gleichmann, J P Nurmi, Colin D Bennett, Christian Stimming, MrTact, Wim Rosseel for their patches and contributions to Artistic Style.

Thanks to SourceForge for giving Artistic Style its home.

Thanks to all the dedicated beta-testers and bug notifiers!

 

 


 

http://www.codeworker.org/Download.html

CodeWorker 4.5.4, 01may2010

Platform

Type

Size

Archive

GnuPG signature

WINDOWS 98/2000/NT/XP

binaries

667086

CodeWorker_WIN4_5_4.zip

CodeWorker_WIN4_5_4.zip.asc

Any platform (?)

sources

3278840

CodeWorker_SRC4_5_4.zip

CodeWorker_SRC4_5_4.zip.asc

Documentation

Type

Size

Document

Reference Manual

892598

CodeWorker.pdf

Reference Manual

-

Online documentation

Tutorial

-

Practice of parsing and code generation for generative programming

Tutorial

French

Automatiser le développement d'applications; parcours découverte

 

Last Java interface for CodeWorker (version 4.5.4)

Platform

Type

Size

Archive

WINDOWS 98/2000/NT/XP

binaries

725533

CodeWorker_Java.zip

Any platform (?)

The sources are located in the directory "java/src" (download CodeWorker sources). Please read this page about the Java interface for more information.

 

Last .NET assembly of CodeWorker (version 4.5.4)

Platform

Type

Size

Archive

WINDOWS 98/2000/NT/XP

binaries

1775507

CodeWorker_NET.zip

Any platform (?)

To compile it for Mono, the sources are located in the directory "cs/src" (download CodeWorker sources). Please read this page about the .NET assembly for more information.

 

Changes

Date

Type

Caller

Description

30apr2010

feature

-

Manual control against multiple inclusion of a script file: use the #if existFunction preprocessor directive.

30apr2010

feature

-

Preprocessor directives are enriched with #if predicate ... #else ... #end.

 

 

 

 

 

 

 


 

http://www.codeworker.org/Links.html

Generative programming

Summer School, june 2002

The summer school aims to give a comprehensive overview of GP as a modern software development methodology. The lectures are given by internationally recognized experts of the area.

Generative Programming Wiki

Definitions, stories and a lot of other topics about Generative Programming.

GPCE'03

Second International Conference on Generative Programming and Component Engineering (GPCE'03) .

Software Factories

A software factory is a product line that configures extensible development tools with packaged content and guidance, carefully designed for building specific kinds of applications.

 

Domain-Specific Modeling

DSM Forum

The DSM Forum exists to spread the knowledge and know-how of Domain-Specific Modeling. DSM raises the level of abstraction beyond programming by specifying the solution directly using domain concepts.

MetaEdit+

A DSM tool to generate full production-quality code from high level design models.

GME: the Generic Modeling Environment

The Generic Modeling Environment is a configurable toolkit for creating domain-specific modeling and program synthesis environments.

Domain-Specific Languages

Domain-Specific Languages - an Overview.

 

Aspect-Oriented Programming / Subject-Oriented Programming

Getting started with AspectJ

An AspectJ tutorial.

An Overview of AspectJ

Another AspectJ tutorial.

Aspects, Concerns and Java

AspectJ may take some getting used to, but aspect-oriented programming can be a nice complement to object-oriented programming.

Aspect C++: language proposal

This paper intends to extend the AspectJ approach to C/C++, to facilitate aspect-oriented programming with C/C++.

AOSD.net

It provides practitioners and researchers a comprehensive source of information about Aspect-Oriented Software Development.

Subject-oriented programming

Subject-oriented programming is a program-composition technology that supports building object-oriented systems as compositions of subjects.

 

Code generation

Program generators with XML and Java

The website of a book written by Craig J. Cleaveland, which presents a way to generate source code.

Code Generation Network

Articles, resources, and forums about the code generation, maintained by Jack D. Herrington, the author of Code Generation in Action.

Software Generators

This site focuses on the topic in general and the Anticipatory Optimization Generator (AOG) in particular. AOG is a system for translation Domain Specific Languages (DSLs) into efficient code.

Code Generation is a Design Smell

Free discussion and (sometimes insolent) opinions about advantages and drawbacks of code generation.

When less is more

A return on experience where code generation gave satisfaction (XML + GSLgen).

A use of CodeWorker is proposed about chess and PGN (format for describing chess games).

 

 

 

 

 


 

 Comand to format java code http://www.peterfriese.de/formatting-your-code-using-the-eclipse-code-formatter/

 

 

<think>好的,我现在需要帮助用户了解Simulink中代码生成的路径设置方法。首先,我得回忆一下自己之前学过的相关知识,或者查找相关的参考资料。用户提到了几个引用,我需要结合这些内容来组织答案。 首先,用户提供的引用[1]提到代码生成的路径是Optimization → Signal and Parameters → Code generation。这可能涉及到模型配置参数中的路径设置。我需要确认在Simulink中如何进入这些设置。通常,用户会通过Configuration Parameters窗口来调整代码生成选项。 然后,引用[2]提到工具链默认即可,但内联和可调参数会影响参数的传递方式。这里可能需要解释路径设置中的参数传递选项,比如是否使用结构体或直接行参传递。这可能与代码生成优化有关,影响生成代码的结构。 引用[3]指出将系统目标文件从grt.tlc改为ert.tlc可以减少代码量。这也属于路径配置的一部分,因为系统目标文件的选择决定了代码生成的模板和结构。因此,在路径配置中,用户需要正确设置目标文件的位置或类型。 接下来,我需要将这些信息结构化,分步骤说明路径设置的方法。可能需要按照以下步骤: 1. 打开Configuration Parameters。 2. 导航到Code Generation相关选项,比如系统目标文件设置。 3. 调整Optimization或Signal and Parameters下的选项,如内联参数、代码生成路径等。 另外,用户的问题是关于路径配置的具体方法,所以需要明确说明每个步骤的位置和选项名称。例如,设置系统目标文件为ert.tlc的位置在Code Generation选项卡下,而内联参数可能在Optimization部分。 还要注意是否需要指导用户如何保存这些配置,或者是否需要指定输出文件夹的路径。比如,生成的代码默认保存在当前模型的根目录下,但用户可能需要自定义输出路径,这可能在Code Generation的选项中有设置。 另外,用户提供的引用中提到了信号和参数的传递方式,这可能涉及到代码生成选项中的参数打包设置,比如选择结构体还是单独变量。需要将这些内容融入路径配置的步骤中,说明不同选项的影响。 最后,确保回答符合用户的要求:结构清晰,步骤明确,引用正确。同时生成相关问题,帮助用户进一步了解相关主题。</think>在Simulink中配置代码生成路径需通过模型参数设置实现,具体步骤如下: ### 一、基础路径配置 1. **打开配置界面** 在模型界面按`Ctrl+E`打开`Model Configuration Parameters`,选择`Code Generation`选项卡 2. **设置系统目标文件** 将`System target file`从默认的`grt.tlc`改为`ert.tlc`(适用于嵌入式系统),可显著减少生成代码量[^3] 3. **指定输出路径** 在`Build process`子选项卡中设置`Build directory`,默认路径为`当前模型目录/模块名_ert_rtw` ### 二、关键参数路径 $$ \text{配置路径} = \text{Optimization} \rightarrow \text{Signal and Parameters} \rightarrow \text{Code Generation} $$ 1. **参数传递方式** - 勾选`Inline parameters`将参数硬编码到代码中 - 取消勾选则生成可调参数(通过结构体传递)[^2] 2. **信号存储优化** 在`Signal storage reuse`启用内存复用,可减少全局变量数量 ### 三、工具链设置 1. 保持`Toolchain`为默认`Automatically locate an installed toolchain` 2. 在`Templates`中可自定义代码文件头信息
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值