Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [Dltk-dev] equals() in AST nodes

Resolving this issue using ASTNode.equals() is not a good idea. Actually, AST nodes that represent both case statements are different, so needed check must be done somewhere else in your semantic analyzer.

Are there any other cases? Right now I'm running unit tests to see whether everything works without equals().

On Wed, Jun 10, 2009 at 5:09 PM, Charles Doucette <cdoucette@xxxxxxxxxxx> wrote:
There is an issue with equals.
Consider the following statement:

int i=2;
int j=0;
switch (i) {
case 2:
       j=1;
       break;
case 2:
       j=2;
       break;
}

One of our users wanted us to do semantic checking to determine if the second case statement was "equal" (equivalent) to the first. If so, we should flag it as a duplicate. Thus, I wanted to use ASTNode.equals to check for the duplicate node. Unfortunately, equals fails since each node includes the start position within the buffer - and those aren't equal.

It would be useful to have a method that could be used to indicate the everything but position was equal. I'm not sure what such a method should be called.

Chuck


On Jun 10, 2009, at 9:28 AM, Michael Spector wrote:

Hi All,

Is there any reason to have equals() methods in basic AST nodes implemented in DLTK core?
I guess it ASTNode should have the following to disallow weird and useless implementations of equals() in class hierarchy:

       public final boolean equals(Object obj) {
               return this == obj;
       }

       public final int hashCode() {
               return super.hashCode();
       }

What do you think?

Thanks,
Michael
<ATT00001.c>

_______________________________________________
dltk-dev mailing list
dltk-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/dltk-dev


Back to the top