AdaCore / gnatstudio

GNAT Studio is a powerful and lightweight IDE for Ada and SPARK.
399 stars 52 forks source link

Finalizable and pragma Extensions_Allowed (All_Extensions) #179

Closed evanescente-ondine closed 3 weeks ago

evanescente-ondine commented 1 month ago

Hi, I'm an Ada student which likes to use the latest syntax in my exos, at least whenever it seems sound. Here it is about the new generalized finalization, bebcause I don't like making tagged types when I want a feature wholly unrelated to object programming.

procedure Initialize (N: in out Pack);
type Pack (Number: CardNumber := 52) is record
    List: CardArray(1..Number);
end record
    with Finalizable => (Initialize => Initialize);

card_package.ads:33:22: warning: "Finalizable" is not a valid aspect identifier [enabled by default]

I know I could do this differently... and used to do, with a default value for List. But since it's abouit initialization, I thought I could use, well, real initizalization instead.

pragma Ada_2022;
pragma Extensions_Allowed(All);

I have "All" because otherwise I get

card_package.ads:2:27: error: argument for pragma "Extensions_Allowed" must be "On" or "Off" or "All"

Not normal, so I can't get the experimental features ? My version is GNAT 13.3.0

Thanks.

michaelayres commented 1 month ago

Do the lines of code you show appear in the same sequence in your program? Everything is contained with the procedure and thus has limited visibility outside of the procedure. That's not an issue, just in curiosity to me, For example PACK is used as a parameter (default IN) in procedure definition and execution,but that same type is later declared in the procedure. Will that even work? Would not declarations be better placed in a package spec file .ads and then your procedure in the package body, .adb? I think it's fundamental in Ada, coming from Pascal that types and variables have to be declared in the declaration section - of either a package spec or procedure/function specification before the algorithmic code of the proc/function.

evanescente-ondine commented 4 weeks ago

Sorry, I wasn't clear and wasted your time. Let's have another go: This is on your website:

Attention: You can activate the extended set of extensions by using either the -gnatX0 command line flag, or the pragma Extensions_Allowed with All_Extensions as an argument.

This is a sample of code that fails. -gnatxo makes no difference.

pragma Ada_2012;
pragma Extensions_Allowed (All_Extensions);
procedure Essai is
    type Pack is null record with Finalizable => (Initialize           => Init);
    procedure Init (N: in out Pack) is null;
begin
    null;
end Essai;

with this message:

essai.adb:2:28: error: argument for pragma "Extensions_Allowed" must be "On" or "Off" or "All" essai.adb:4:39: warning: "Finalizable" is not a valid aspect identifier [enabled by default] gnatmake: "essai.adb" compilation error

raph-amiard commented 3 weeks ago

Hi evanescente,

Our docs are live generated from the nightly version of our compiler and tools. The options you are refering to are just not yet available in the community compilers. For community compilers we follow the GCC release schedule, so those should be available in the next release!

Kind regards