[antlr-interest] RE: C++ version, == nullAST

David Barron david.barron at synergex.com
Thu Oct 4 07:31:10 PDT 2001

STL uses "empty" as a predicate to determine whether the container is empty.
This should be easy to add to template RefCount < T > :

// (pseudo code)

RefCount::empty(const T &x) const
	return (T.pointer == NULL);

Making this a method of RefCount should make things more efficient.
Checking a pointer against 0 should be faster than checking someAST ==

STL uses "clear" is used to clear a container (or part of it).  It may not
make the code more efficient, but it would make it closer to STL, which
should make it easier for C++ people to use.


-----Original Message-----
From: Ken Lidster [mailto:ken at synergex.com]
Sent: Wednesday, October 03, 2001 3:25 PM
To: 'antlr-interest at yahoogroups.com'
Subject: RE: [antlr-interest] C++ version, == nullAST


I haven't worked with this code for a couple of years, but I believe this
relates to the reference counting. First, I seem to recall that in this
particular smart pointer implementation the only way to 'release' an
associated address (actually, a private, encapsulating, reference counted,
pointer object) was by either assigning another smart pointer to it, or via
destruction when the smart pointer object goes out of scope. Thus, equating
the empty nullAST object was an explicit release of the associated pointer.

Second, I believe the default extractor for the base reference class
(template RefCount<T> I think) was the address of the encapsulated pointer
object, or zero if there was nothing. Since there wasn't an explicit
clearing method and, as you noted, all of the releases were accomplished via
an equate to nullAST, the 'someAST == nullAST' had to be used to determine
if someAST was "empty".

I remember thinking back then that I would have preferred (as I mentioned
above) something like an explicit clear() or empty() method. The operation
'someAST.clear()' seems more intuitive to me than 'someAST = nullAST'. This
would also have allowed 'someAST == 0', or even '!someAST' to be true when
the smart pointer was empty. But, what we had worked and there were
deadlines to be met. You know how that goes, I'm sure.


-----Original Message-----
From: Ruslan Zasukhin [mailto:sunshine at public.kherson.ua]
Sent: Friday, September 28, 2001 2:25 PM
To: Ric Klaren; antlr-interest at yahoogroups.com
Subject: [antlr-interest] C++ version, == nullAST

Hi Ric,

I also note next issue.
What sense to have in C++ version special global variable

    RefCount nullASt


Later there is many coe that use it for comparison

    if( someAST == nullAST )

At first I did think this is again, "way of Java"...
but in Java code I see

    if( someAST == null )

So I think we must throw out from C++ version this nullAST.
This make code more clean, more similar to Java version and little faster.

    if( someAST == nullAST )
                 ^^^^^^^^ here work operator that return AST*

    if( someAST == 0 )
                   ^^^^ zero overhead.

Best regards,
Ruslan Zasukhin


e-mail: ruslan at paradigmasoft.com
web   : http://www.paradigmasoft.com

To subscribe to the Valentina mail list
send a letter to valentina-on at lists.macserve.net


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list