comp.lang.ada
 help / color / mirror / Atom feed
* pragma ELABORATE not allowed (Sun Ada)
@ 1994-10-18 12:33 Ulf Stenhaug
  1994-10-18 14:32 ` Bob Duff
  0 siblings, 1 reply; 2+ messages in thread
From: Ulf Stenhaug @ 1994-10-18 12:33 UTC (permalink / raw)



We use what we think is an elegant solution for configuring an
application, but after shifting compiler that gave us problems.

Can anybody give advise?


We enter configurable parameters in a file and use a 'configure'
package which provides the values found on the file. Simplified
excerpts:

package body configure is
	config_database : t_config_database;
	procedure read_config_file is separate;
	task protect_config_db is 
		entry reserve;
		entry release;
	end;
	task body protect_config_db is
		read_config_file;
		loop
			select
				accept reserve;
				accept release;
			or
				terminate;
			end select;
		end loop;
	end protect_config_db;

	-- Body of the function defined in package spec:
	function value_of(name : string) return integer is
		found_value : integer;
	begin
		protect_config_db.reserve;
		-- search in the 'database' for the name ...
		found_value := config_database(.....);
		protect_config_db.release;
		return found_value;
	end value_of;
end configure;

with configure;
package rename_config is
	-- I don't think that this renaming is of importance
	-- in this context, but this is how we do it ...
	function value_of ( name : string ) return integer
			renames configure.value_of;
end rename_config;

Then this is used for instance in the following way:

with rename_config;
with other_packages_which_also_use_configure;
program main is
	task type t_a_task is
		entry an_entry;
	end t_a_task;
	for t_a_task'storage_size use
		rename_config.value_of("stack_size_of_a_task");
	a_task : t_a_task;
	task 
	begin
		--
	end;
end main;

For this to work, the 'configure' package naturally has to be
elaborated first. While we used the Verdix Ada Compiler v. 6.0.3(c)
we had no problems. When we compiled our application with the
Sun Ada Compiler v. 1.1(f) the program crashed (with 'program_error'
exception), and the debugger refers to ARM 3.9(5) and says that
  "subprogram value_of called before body has been elaborated".

When we try to isolate the problem and strip off the application
stuff that is irrelevant for the problem, the error situaion vanishes.

Now to the real problem: We insert "pragma ELABORATE(rename_config)"
after the with-statement, but then the compiler refers to ARM
appendix B and complains that
  "This pragma not allowed in this context."

Why is it not allowed? What can we do??????

Regards Ulf Stenhaug



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: pragma ELABORATE not allowed (Sun Ada)
  1994-10-18 12:33 pragma ELABORATE not allowed (Sun Ada) Ulf Stenhaug
@ 1994-10-18 14:32 ` Bob Duff
  0 siblings, 0 replies; 2+ messages in thread
From: Bob Duff @ 1994-10-18 14:32 UTC (permalink / raw)


In article <CxvC8G.7sw@trh.cap-computas.no>,
Ulf Stenhaug <ust@trh.cap-computas.no> wrote:
>package body configure is
...
>end configure;
>
>with configure;
>package rename_config is
...
>end rename_config;
...
>with rename_config;
>with other_packages_which_also_use_configure;
>program main is
 ^^^^^^^ You mean "procedure" or "package body" here.
If it's a procedure (the main subprogram), then there should be no
problem, since everything is elaborated before the main subprogram is
called.  So I assume this is really a package.

Elaboration order is different on different implementations (within some
constraints).  So it's not surprising that the code happened to work on
one compiler, and you got Program_Error on the other one.

>Now to the real problem: We insert "pragma ELABORATE(rename_config)"
>after the with-statement, but then the compiler refers to ARM
>appendix B and complains that
>  "This pragma not allowed in this context."
>
>Why is it not allowed? What can we do??????

In Ada 83, you have to put all the pragmas Elaborate *after* all of the
with_clauses and use_clauses.  This restriction has been removed in Ada
9X.

You really need to elaborate the body of Configure (not just
Rename_Configure) before the body of package Main.  This means you need
to say pragma Elaborate(Configure).  But in order to do that, you have
to add "with Configure;".  That's a real pain, because Main doesn't
reference anything in Configure, and so shouldn't have to mention it in
a with_clause.  This is a flaw in the language design.

This problem has also been solved in Ada 9X.  In Ada 9X, you can say
pragma Elaborate_All(Rename_Configure).  This is just like pragma
Elaborate, except that it automatically applies to everything the spec
and body of Rename_Configure depends on.  In Ada 9X, you should always
use pragma Elaborate_All instead of Elaborate, except in certain rare
circumstances involving mutually recursive packages, where Elaborate_All
would cause a circularity.

Ada 9X also has some other pragmas for controlling elaboration.  Pragma
Preelaborate (and pragma Pure) cause the package spec and body to be
elaborated "first" (before non-preelaborated things).  Pragma
Elaborate_Body, means don't elaborate anything in between the spec and
body of this package.  All of these reduce your chances of getting
Program_Error because you called something before it was elaborated.
-- 
Bob Duff                                bobduff@inmet.com
Oak Tree Software, Inc.
Ada 9X Mapping/Revision Team (Intermetrics, Inc.)



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1994-10-18 14:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-10-18 12:33 pragma ELABORATE not allowed (Sun Ada) Ulf Stenhaug
1994-10-18 14:32 ` Bob Duff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox