CDTFundamentals¶
The following screenshot shows some details of the Photran plugins for the Fortran language. Photran provides support for Fortran using the extension mechanisms of CDT. It is worth mentioning that, although there is a Fortran perspective, files and projects have C decorators.
Language¶
Firstable, we have to provide a language extension. For this purpose we use the extension point ##org.eclipse.cdt.core.language##. We implement a class that extends AbstractLanguage. This class must implement, among others, a method that returns an IContributedModelBuilder. This ModelBuilder will be used by CDT to build the model that will be shown in Outline and C Project Explorer.
The Photran project defines an extension point that lets them provide different model builders for different purposes. For instance, there is a simple ModelBuilder and an advanced one. In the aforementioned method, they choose an advanced model builder if available. If there is no advanced model builder available, they choose the simple one. The user can also specify in the preferences which one he/she wants to use.
Currently, Pascaline provides a simple model builder. Just expand some pascal source file to have a look at it. It is completely based on a lexer.
Model Builders¶
Basic Model Builders¶
Basic model builders my be based on patterns. Code is read one line at a time, and a text search based on these patterns is performed. This is well suited for languages with a very strict syntax such as Pascal. Patterns can detect definitions of functions, classes, registers, and so on.
Model builders like this doesn't produce the whole AST, but just a basic view of the source. This could suffice to populate the Outline.
Parsers¶
General view of the source parsing process in CDT
Builders¶
Builders are responsible of building the different artifacts that results from building the project. The building process may compile the whole project or just some files. The Eclipse building framework determines if a full build is required or just a partial one (incremental build).
Managed Build System¶
This article explains how to extend the CDT's Managed Build System.
Other plugins may provide their own toolchains. A toolchain is a set of tools that are invoked in the given order over a set of resources. These tools may be already defined ones (like the ones provided by CDT) or you can configure your own tools (like the FreePascal compiler) which can then be used within your toolchains.
Both tools and toolchains can be defined by extending org.eclipse.cdt.managedbuilder.core.buildDefinitions. You may also define projectTypes which use a concrete toolchain that can be tuned for projects of a particular type. The image shows the six projectTypes provided by Photran.
Usually, a generic toolchain is defined, which uses a concrete set of tools. Then several projectTypes that use the same toolchain can be defined. For instance, a projectType may produce a shared library, whereas other produces a static one. This can be done by reusing the toolchain, but reconfiguring some of the tools it contains (for instance, adding an option to a tool to change from static to shared).
Launcher¶
The launcher allows us to configure the way programs are executed in both run and debug modes. Using a launcher has important advantages. For instance, launching configurations are saved by the environment, so that a user can use a given launch configuration several times. This is transparent for us and is performed by Eclipse.
To define a launcher we need to use four extension points.
org.eclipse.debug.core.launchConfigurationTypes¶
- provides a name for the launcher (FreePascal Local Application)
- describe the modes in which a launch can be used (run, debug, profile)
- specify the class that implements the delegate that is in charge of preparing the launch (delegate)
Among other things, the delegate must prepare a configuration for launching the program. As long as Pascaline extends CDT, we can use much of the functionality provided by CDT, like the delegate org.eclipse.cdt.launch.internal.LocalCDILaunchDelegate.
org.eclipse.debug.ui.launchConfigurationTabGroups¶
Provides the class that is in charge of creating the different tabs that appears in a launch configuration. As was stated before, we can make use of LocalRunLaunchConfigurationTabGroup, provided by CDT, and overwrite the method createTabs to provide our own tabs to the configuration. We can even make use of some available classes for tabs:
- Arguments tab: CArgumentsTab (CDT)
- Environment variables: EnvironmentTab (org.eclipse.debug.ui)
- Debug tab: CDebuggerTab (CDT)
- Source tab: SourceLookupTab (org.eclipse.debug.ui)
- Common tab: CommonTab (org.eclipse.debug.ui)
org.eclipse.debug.ui.launchCOnfigurationTypeImages¶
We can also configure the icon that appears along with the launch configuration type. This extension point allows us to define such icon.
org.eclipse.debug.ui.launchShortcuts¶
Here we have used the CApplicationLaunchShortcut, but we have modified it slightly.Concretely, the method createConfiguration() was modified to choose automatically under windows our CommandFactory for MI commands, which sets "new-console on" for gdb in order to open a windows console where the program shows its outputs and reads its inputs. This solves some problems that appear due to the fact that gdb cannot use a pty in windows.
New... Wizards¶
It is usual to provide several types of wizards to create artifacts related with the language:
- New projects
- New source files
- Source folders
- Text files
- Folders