Boost logo

Boost-Build :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-03-27 01:42:44


Modules are always entered in a nested scope:

module <name> { ... }

So there is always an outer and an inner module.

A variable X can be established as a module global by assigning to it
when there is no enclosing local declaration of X within the module.
[There is an implicit open brace just before each local variable
declaration and a corresponding implicit close brace just before the end
of the actual scope containing the local variable declaration] Thus:

module A
{
x = 1 ; # x is global in A
local y ;

module B
{
module A
{
y = 2;
ECHO $(x) ; # prints 1

local y = 3 ;
ECHO $(y) ; # prints 3
}
}
ECHO $(y) ; # prints 2
}

This is consistent with classic Jam behavior; just eliminate the module
declarations to see that.

So what happens when variables are declared in B?

I think I have a simple and elegant solution:

Every module has its own variable space. Within a module, variable
values and settings are exactly as though all scopes inside other
modules have been eliminated. This includes the global module. Thus, no
module ever has access to globals or locals from another module. The
only way to pass values across module boundaries is via rule arguments
and return values. Example:

module A
{
x = 1 ; # x is global in A
local y ;

module B
{
ECHO $(x) ; # prints blank line
local x = BANG ;
y = BOOM ; # y is global in B
rule printxy { ECHO $(x) $(y) ; }

module A
{
y = 2;
ECHO $(x) ; # prints 1

local y = 3 ;
ECHO $(y) ; # prints 3
B.printxy ; # prints BANG BOOM
}
}
ECHO $(y) ; # prints 2
B.printxy ; # prints BOOM
}

I think this will considerably simplify the code for handling module
variables. Feedback, please!

-Dave

+---------------------------------------------------------------+
David Abrahams
C++ Booster (http://www.boost.org) O__ ==
Pythonista (http://www.python.org) c/ /'_ ==
resume: http://users.rcn.com/abrahams/resume.html (*) \(*) ==
email: david.abrahams_at_[hidden]
+---------------------------------------------------------------+

 


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk