1

Is it possible to have a different file name for a package than its actual name? I have tried to use the pragmas below but get errors like "pragma source_file_name_project argument has incorrect identifier"

package Parent_With_Very_Long_Name is end Parent_with_Very_Long_Name;
...
package Parent_With_Very_Long_Name.Child is
    pragma Source_File_Name_Project("parent-child.ads");
end Parent_With_Very_Long_Name.Child;
Roger Wilco
  • 102
  • 2
  • 12
  • Both of those links tell you *not* to use `Source_File_Name_Project`. That said - I assure you that `Source_File_Name` works, but if you want us to help you you **must** show us what you actually wrote, and what file you wrote it in. And, for preference, the actual error message you got. – Simon Wright Oct 03 '13 at 06:31

2 Answers2

3

The actual storage of Ada source text is technically an implementation detail of the compiler.

Looking at the file names your compiler expects, I would guess that you are using GNAT (GCC-Ada). GNAT allows you to override the default naming scheme in project files:

project Short_File_Names is
   package Naming is
      for Specification ("Parent_With_Very_Long_Name.Child")
        use "parent-child.ads";
   end Naming;
end Short_File_Names;
Jacob Sparre Andersen
  • 6,733
  • 17
  • 22
3

The documentation for pragma Source_File_Name says the syntax is

 pragma Source_File_Name (
   [Unit_Name   =>] unit_NAME,
   Spec_File_Name =>  STRING_LITERAL,
   [Index => INTEGER_LITERAL]);

 pragma Source_File_Name (
   [Unit_Name   =>] unit_NAME,
   Body_File_Name =>  STRING_LITERAL,
   [Index => INTEGER_LITERAL]);

so the reason the compiler is complaining is that you've used incorrect syntax. Using the correct syntax, that would be

package Parent_With_Very_Long_Name.Child is
   pragma Source_File_Name 
     (Parent_With_Very_Long_Name.Child, Spec_File_Name => "parent-child.ads");
end Parent_With_Very_Long_Name.Child;

but the compiler now says

parent-child.ads:2:01: incorrect placement for configuration pragma "Source_File_Name"

The proper placement for this configuration pragma is before the unit:

pragma Source_File_Name 
  (Parent_With_Very_Long_Name.Child, Spec_File_Name => "parent-child.ads");
package Parent_With_Very_Long_Name.Child is
end Parent_With_Very_Long_Name.Child;

which is all very well, but how are other units going to know this? (GNAT has a source-based compilation model). One answer is to put the pragma in a configuration file, gnat.adc by default. A better answer is to use GNAT project files and package Naming, as suggested by Jacob Sparre Andersen.

Simon Wright
  • 25,108
  • 2
  • 35
  • 62
  • Yes, I am getting different errors now related to the units not knowing how to include each other. From what you describe a configuration file or additions to the project file are needed to work around this? Errors: "file parent-child.ads does not contain expected unit. Expected unit parent.child, found unit Parent_with_Very_Long_Name.Child" – Roger Wilco Oct 03 '13 at 13:20
  • 1
    I don't understand why you got that particular error; I just compiled the source as in the answer without error. And yes, you need a configuration file or a project file. – Simon Wright Oct 03 '13 at 13:42