Include one Dafny file in another - dafny

I want to reuse the same Dafny code in several programs. Is it possible to include one Dafny file in another? The manual does not describe any way to do it.

Yes, in December 2013 support for an "include" statement was added to Dafny, the syntax is:
include "Includee.dfy"

Related

Autocomplete punctuation using grammar

I'm working on a tool that is able to autocomplete the necessary literals defined in a grammar. For example: in C# if a programmer enters: for with a space after it, then it's entirely possible to parse the code, determine that the programmer has started a for statement and autocomplete the necessary punctuation: ( ; ; ).
The more I think about the problem, the more I think there must already be a solution for it, because it's such a common use case, but I can't find anything.
Is there a tool that can do this using a given grammar?
If you don't mind using ANTLR v3 instead of v4 you can use Xtext in order to generate an editor that features auto-complete and error-highlighting. This will happen in form of a plugin for eclipse and apparently also for IntelliJ IDEA.
If you want to use a different IDE or simply want to make use of ANTLR v4's powerfull features you could still have a look at the Xtext Sources as they have to do what you are searching for in order to provide the above mentioned features properly...
This package looks very promising at first glance... You might find the respective code in there.
Be aware though that Xtext is mainly written with Xtend so you either have to do so as well or you have to rewrite it a bit

How to obtain a file with the content of all include files explicitly included?

George "Mirage" Bakhtadze, the author of Cast II engine, has wrote about an include-based technique which can be used to create generic containers and algorithms. The source is avaiable from the repo at Github. For me, his include-based technique is very interesting and useful, because it can be used for older Delphi and it is compatible between Delphi and Free Pascal (and non-Windows OS ready).
It would be more useful for me if the _GenVector written in "gen_coll_vector.inc" has Sorted & Duplicates properties and related behaviors (behaving the same way as in TStringList).
However, it is less obvious for me to insert the code when there are many include directives (I wonder how George managed this in the first place). Therefore, I wonder whether it is possible to obtain a sample file with all include files explicitly included ? It might be more straightforward for me to start from there.
I mean that there is certain built-in pre-processor that works before the actual compiling and whether there is a way to keep these intermediate files ?
Delphi does not use a pre-processor. It is (and always has been, since Turbo Pascal days) a single-pass compiler. There is no intermediate step. When you {$I} to include files, they are inserted in place in memory during the compilation process. Therefore, there is no "intermediate file" that can be kept.

any tools which scan code and give a list of functions which call a given function

here's my problem, I'm tidying up some old code which I've modified over the years and removing redundent functions,
I can do it the slow way & comment it out and see if the compiler throws an error.
But I'm just wondering if there are any tools which can which scan code and give a list of functions which call a given function.
I Had a look in ge-experts & icarus, but they only do this at the level of units & classes not down to functions.
any suggestions welcome,
many thanks, Brian
Recent versions of Delphi have "Search for References" available via context menu or Ctrl-Shift-Enter. This has the advantage over a simple "search in files" that it will find only references to the current function under the cursor and not also any function or other identifier with the same name.
Compile your project. Then, in the IDE, those lines that are accessed (rather than being dead code) will have a blue dot in the left margin:
No method is perfect, limitations of the one below are these:
the .MAP file will include functions that the linker cannot eliminate (for instance overrides of methods in classes touched by your code)
it will only give you method names, but if methods are overloaded multiple versions of these methods could be used
The big pro over using .MAP files is that they are easier to scan than blue dots in the code editor.
So it does answer your question to provide a list of functions. But that might not actually what you are after (:
Method using .MAP file:
change your project to include a detailed .MAP file
rebuild your project
the directory of your .EXE file now will include a .MAP file
scan the .MAP file for function names that are included in the .EXE
That .MAP file will exclude functions eliminated by the compiler and linker.
Those are a good indication of what 'dead' code you have.
In a similar way, you could use the JDBG information. That contains more context, but also requires you to write some tooling yourself.
For Pascal this is trivial. First make a list of all the functions, then for each function search for it in the text not following the word "function" and followed by a "(". Awk would be a good tool for doing this.
If your Delphi version is 2007 (or may be prior to it?), I strongly suggest you to consider using DGrok: Give it a try and you will see how capable it is (The demo app will tell).
As it was pointed out by the author, you still need to implement symbol table support, so that the tools can do refactorings or Find References: Roll your own...
Don't worry if you are stuck to Delphi, please head to
PasParse (The Delphi port of the DGrok parser that was originally written in C# !) by Turbo87.
Notice that Turbo87 has forked the original Joe White's Dgrok (latest release in 2008) (Update to VS2010 and add some documentation for LexScanner).

Supply method bodies in Tools API

Years ago, I wrote a code template that took a few simple parameters (points) and produced a class skeleton. Since some of the method bodies had code in them, I couldn't call InvokeClassCompletion and just placed the implementations with the declarations (user had to move them).
It has occurred to me that I can write a code template script engine to insert these methods in the correct position, but I don't see how I'm supposed to navigate the file. There are declarations for IOTAEditReader and IOTAEditWriter in ToolsAPI.pas, but I'm guessing there is a step missing - certainly I don't need to manually parse the Delphi code just to find the implementation section?
Does anyone have experience with it?
The IDE has plenty of parsers in it, but not one is made available for IDE plugins (ToolsAPI). So you have to write your own parser or use an existing one like http://delphiblog.twodesk.com/using-the-castalia-delphi-parser
You might find that GExperts or CNPack contains almost all the code you need, in one of its editor wizards.
If not, then, those two are the best reference I know for writing IDE plugins. As far as writing parsers, see Andreas' answer.
If you just want better code templates, you could consider buying Castalia, as it has an improved code template feature over the builtin delphi IDE plugin features. Castalia internally uses the Castalia delphi parser mentioned by andreas. It's quite good.

Tool that shows unit dependencies for Delphi 2010 or Delphi 7 program

We're trying to untangle a hairball of 100's of units, removing some.
It would be helpful if there was tool that would show us what units were explicitly using unit X.
Penganza doesn't seem to have a report that does that. (Although it has lots of other useful reports.)
Can anyone suggest a tool or strategy for doing this, other than just hiding unit x and then hitting F9 ... repeatedly?
MMX (Model Maker Code Explorer) has a nice unit dependency analyzer (it is especially good at detecting cycles).
For more details, see this answer.
--jeroen
From a similar question here
You might want to take a look at at
CnPack.
CnPack includes a Uses cleaner
wizard wich hasn't failed me yet.
GExperts can show Project Dependencies.
Peganza Pascal Analyzer can do the work. I haven't worked with it much, but a former dev here wrote a system that uses PAL to do the analysis, then dumped the results into a database, and then there's a browser app that lets you enter a unit name and it returns the list of units affected, whether they would need to be rebuilt if the unit changed, or if the interface changed. We use lots of BPLs so you can sometimes change a unit and you don't have to re-build other binaries that use your unit, unless the interface changed. This saves us lots of work (hundreds of BPLs and EXEs).
Chris
Headway Software's Structure 101g (and Restructure 101g) can do that really well, with the Delphi plugin.
Disclaimer: I wrote the flavors to analyze Delphi. I use them professionally, helping clients.
We've just released a freeware utility that does exactly what you need plus quite a bit more. It's called the Delphi Unit Dependency Scanner (DUDs) and you can download it here: http://www.easy-ip.net/delphi-unit-dependency-scanner.html
Sorry it's a bit late!
I was going to mention Icarus, but when I googled them I got this stack overflow answer, which you might want to check out.
Then again, sometimes I just like to delete my whole Unit Output Directory, then count my new DCU's, and that works too.
The reason you may like Icarus and not GExperts is that it doesn't rely on you to have properly maintained the uses statements in your project file.
A newcomer in this field is the Delphi Plugin for Sonar. It does not list unit dependencies but can find unused files and "dead" code (and more).
Implemented features:
Counting lines of code, statements, number of files
Counting number of classes, number of packages, methods, accessors
Counting number of public API (methods, classes and fields)
Counting comments ratio, comment lines (including blank lines)
CPD (code duplication, how many lines, block and in how many files)
Code Complexity (per method, class, file; complexity distribution
over methods, classes and files)
LCOM4 and RFC
Code colorization
Unit tests reports
Assembler syntax in grammar
Include statement
Parsing preprocessor statements
Rules
Code coverage reports
Source code highlight for unit tests
“Dead” code recognition
Unused files recognition

Resources