• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

language/duchain

Implementing Definition-Use Chains for a specific language

Overview | Design | Implementing | Using

Creating the Definition-Use Chain

To create a definition-use chain for a programming language, you need the following:

  • a parser for the language,
  • a context builder,
  • a type builder,
  • a declaration builder,
  • and a use builder.

Once you have everything up to the declaration builder, your language's classes, functions etc. will automatically appear in the class browser, and be able to perform limited refactoring.

Once you have the use builder, you will automatically have full support for context browsing.

Code completion support requires further work specific to your language, see Implementing Code Completion

Parser

Parsers in KDevelop can be created in any way as long as they produce an AST (abstract syntax tree). Most supported languages have parsers generated by kdevelop-pg-qt. This is a LL parser generator, and allows you to specify the grammar from which the parser and AST are generated. The parser will also need a lexer, common solutions are to use flex to create one for you, or to create one by hand.

DUChain Builders

The abstract builder classes (detailed below) provide convenience functions for creating a definition-use chain. They are template classes which require 2 or 3 class types:

  • T: your base AST node type
  • NameT: your identifier AST node type, if you have only one, or your base AST node type if more than one exist
  • Base class: your base class, eg. for your use builder, you will usually supply your custom context builder here.

Context Builder

By subclassing AbstractContextBuilder, you will have everything you need to keep track of contexts as you iterate the AST. When a new context is encountered, such as a new block (eg. between {} brackets), create a new context with KDevelop::AbstractContextBuilder::openContext(), and close it with KDevelop::AbstractContextBuilder::closeContext().

Some languages do not need a context to be created for each block, for example languages where declarations are visible after the block in which they were defined (eg. php).

Type Builder

By subclassing AbstractTypeBuilder, you can create types when one is encountered in your AST by calling openType(). Again, you need to closeType() when the type is exited. Complex types are built up this way by creating the type at each node, ie. with int[], first an array type is opened, then an integral type representing an integer is opened and closed, then when the array type is closed, you can retrieve the lastType() and set that as the type which is being made into an array.

Declaration Builder

By subclassing AbstractDeclarationBuilder, you can create declarations when they are encountered in your AST. Usually you will assign the lastType() or currentType() to them within closeDeclaration().

Use Builder

By subclassing AbstractUseBuilder, you can create uses when they are encountered in your AST, and they will be automatically registered with the current context.

Implementing Code Completion

To provide code completion for your language, you will need to implement the following:

Todo:
complete this section

language/duchain

Skip menu "language/duchain"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal