Rename an Ada package

不想你离开。 提交于 2020-01-05 04:00:32

问题


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;
  • Source_File_Name_Project
  • Source_File_Name

回答1:


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;



回答2:


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.



来源:https://stackoverflow.com/questions/19151641/rename-an-ada-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!