Search code examples
compiler-constructionruntimenaming-conventionsadagnat

Why are predefined unit file names in GNAT only 8 characters?


I'm building a runtime for the Arduino Due, based on this work by Brent Seidel. The board uses an Atmel SAM3X8E processor, which as you might notice is a seven-letter name. Brent makes this note in the file a-sam3x8.ads:

--  This package should be called "System.Sam3x8e", but after lots of testing,
--  it seems that for some reason it just wouldn't find the package.  Calling
--  the package "System.Sam3x8" does work.

Indeed, after my own testing, I was not able to build the runtime with the "proper" name. Upon closer inspection, I noticed that all predefined files in GNAT and other BSPs seem to be exactly six letters long, plus the prefix as described in the GNAT documentation on file naming rules. There is also some info there about gnatkr and "krunching" filenames to be a certain number of characters, and even an example of a predefined unit being krunched to 8 characters. However, I can't find any explanation as to why predefined units are shortened.

I suppose to fix this particular case I could name the package System.SAM3X8E and then krunch it or add pragma Source_File_Name, but I'd really rather just have descriptive filenames. In fact, I'd like it if I could rename all the predefined files to use their full names. I know they'd get long, but I'd rather have a long, descriptive names than a six-letter alphanumeric mess.


Solution

  • As noted here, this limitation is an accommodation for 8.3 filenames, comprised of no more than eight characters and an optional extension. As noted here by @Zerte, GNAT came out ca. 1995 with the advent of Ada 95, a time when DOS was still popular and Windows ran atop DOS. Moreover, all file systems have name length limits, while descriptive package names and hierarchy depth don't. Implementations vary in how they accommodate the latter, but GNAT uses the file system.

    Note that gnatkr simply transforms the package name to a file name that meets file naming rules cited in your question.

    $ gnatkr System.Sam3x8e.adb
    s-sam3x8.adb
    

    It should be possible to have a package named System.Sam3x8e in a file named s-sam3x8.ads

    package System.Sam3x8e is…
    

    This would allow other compilation units to reference the full name in a context clause:

    with System.Sam3x8e;