How should this be done? (1.0)

Derek Parnell derek at nomail.afraid.org
Tue Feb 5 23:18:01 PST 2008


On Tue, 05 Feb 2008 21:54:28 -0800, Michael Coupland wrote:

> Correct me if I'm wrong, but I think it has several of the same problems 
> that a normal macro has. 

I see what you're saying. It could be that the future AST macros can help
us with this sort of stuff.


However, it appears that you'd like to define a named fragment of code that
includes arbitrary declarations and executable statements, force that
fragment to be in-lined in one or more places (with possibly parameterized
textual replacement?), and have any error messages refer to line numbers in
the fragment's definition rather than, or as well as, its instantiation
location.

Example syntax (not wedded to this of course).

macro CommonCalculation(alias b1 = defBool1, alias b2 = defBool2)
{
    bool b1;
    bool b2;
        
    void calculate()
    {
        int LocalVal = SomeFn();
        b1 = SomeOtherFunc();
        b2 = AThirdFunction(LocalVal,b1);
    }
}

...

{
    CommonCalculation(commonBool1, commonBool2);
    // do stuff here with commonBool1 and commonBool2
}

...

{
    CommonCalculation();
    // do stuff here with defBool1 and defBool2
}

With messages like ...

test.d(231): Function 'someFn' not defined. Referenced in macro
'CommonCalculation'(line 48).
test.d(493): Function 'someFn' not defined. Referenced in macro
'CommonCalculation'(line 48).


-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
6/02/2008 6:01:14 PM


More information about the Digitalmars-d-learn mailing list