Prism

0. Index

  1. Introduction
  2. Supervision – initial steps
  3. Prism – a leap forward
  4. References

1. Introduction

For the last 15 months or so, I’ve been involved in a spare-time project together with a colleague with the explicit goal of improving programmer understanding of program source code through static program analysis.

Static program analysis, as opposed to dynamic program analysis, happens before the program is actually run – and in our case, before the program is compiled to executable code.

So what do we hope to achieve through static program analysis? In short we hope to provide a view of a program which presents important facts about the code, provides navigation between source code modules and farther along, tries to prove certain properties about parts of the program – for the sake of correctness and efficiency.

The language in question is called C/AL and is a programming language used by the Microsoft Dynamics NAV business software platform.

This work involves several architectural modules; some of which are:

  • I/O: accessing source code files
  • Parser: parsing and lexing source code into abstract syntax trees
  • Folder: in simple terms, a recursion scheme for abstract syntax trees; in object-oriented lingo this is like the Visitor pattern – but in functional category-theoretic-style
  • Index: fast lookup of declaration references across source modules called objects; the index also provides a nicer view of the abstract syntax tree
  • Semantic Analysis: determine the meaning of names using the index for cross-object procedure calls and other references (also called name resolution)

These modules combine to form a powerful software platform for analysing and to some extent transforming program source code.

The infrastructure itself is developed using Microsoft F# – a multi-paradigm but functional-first programming language.

2. Supervision – initial steps

The first tool we built using this static analysis infrastructure is called Supervision[1] and it is available for anyone interested from our homepage[1], and from mibuso[2].

Supervision is a simple-looking program which, given an object text file (a program source file), can produce a hyper-linked, color-coded, interactive set of HTML files (along with CSS and Javascript assets); Supervision is very fast compared to alternatives and gives a very new way of looking at C/AL program source text.

supervision

Procedure calls are hyper-linked to the relevant procedure declarations and in general all declaration references are hyper-linked to their declarations which have been resolved through name resolution.

There are some nice presentational aspects of Supervision too; for example hovering over parameters, all uses of these are high-lighted below – which is a very fast way of gaining an overview; at least for well-factored procedures which do not span multiple pages. The tooltip also shows the number of usages of parameters. In general there are tooltips for almost everything. The reverse is also true: if hovering over a parameter usage inside a procedure the parameter will also be highlighted. Many more such small details are present.

Supervision does suffer from three main disadvantages though:

  • C/AL object source code consists of a meta-structure, a kind of container structure, because the source code is not pure statements and expressions but also things like forms, triggers, table fields, keys, etc. This container syntax is not particularly nice and as Supervision annotates rather than completely transforms the source code, the ugly container syntax is preseved. Some may find that useful but many may not like the “raw” view; unlike Dynamics NAV, however, the raw view shows everything — you don’t have to trawl through several layers of submenus in order to see the code – it’s there, in your face, as we like to say
  • Although Supervision is exceedingly fast (much faster than Developer’s Toolkit, for example); it still needs to translate the source code to a new form rather than just showing the annotated source code directly; this is both a plus and a minus though
  • There is no “find usages” feature like in Developer’s Toolkit and modern tools like Visual Studio

Dispite the limitations of Supervision, we still find it a great tool and there’s not much for the Dynamics NAV ecosystem to rival it. Surely it is non-trivial to build such a tool.

3. Prism – a leap forward

Since analysing the user experience of Supervision and looking at more features, we decided to try and build a more sophisticated application with the GUI to match.

After a period of consideration we decided to build this application using Windows Presentation Foundation (WPF). This is Microsoft’s strategic UI framework. It has been no walk in the park to make WPF play ball; creating a code viewer requires some virtualization techniques to be used which are non-obvious and requires some research to figure out.

Now however, we think we’ve succeeded.

With Prism[3] we can now show the user a fully structured view of the tree container structure inherent in Dynamics NAV source code files and we can do so in a visually pleasing and more easily accessible manner – while maintaining our mantra to put the code not just “at your fingertips” but “in your face”.

prism screen

Prism takes about 20 seconds to access, parse and index all objects in a complete Dynamics NAV database. This is compared to the 20-25 minutes that the now discontinued Developer’s Toolkit takes pre-process a NAV database.

Ironically, the most time-consuming task when using Prism is the export from within Dynamics NAV to an object text file and we can’t do anything about that (well, we actually do have a workaround that may pop up later.)

In addition Prism shows object dependencies with no hessitation. After an object is selected it is immediately clear what other objects refer to it and what objects it itself refers to. We call these two groups of links for “Used By” and “Using”. It is a kind of instant dependency map.

Further, we now have a “Find Usages”  feature. It is possible to, for example, find all usages of a field or procedure and Prism (as well as Supervision) already supports Dynamics NAV 2013.

Certainly we have many more ideas but it’s been exciting to combine static program analysis and user experience into a combined developer productivity tool. There are still ideas left to explore here; in general the Dynamics NAV tools ecosystem feels a little under-nourished – although it is beginning to catch up since the 3-tiered architecture and the RTC client.

In conclusion it has been fun and educational to explore program semantics and static program analysis. It certainly gives deeper insigts into the Dynamics NAV platform. So far our output has been two tools which believe can really help NAV programmers in their day-to-day work.

4. References

  1. Supervision
  2. Mibuso
  3. Prism
Advertisements

About xosfaere

Software Developer
This entry was posted in C/AL, Computer Science, Datamodel, Declarative, Imperative, Navision, Paradigm, Program, Software, Technical and tagged , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s