forked from jasder/antlr
Improved SemanticContext.hashCode(), add @Override annotations
This commit is contained in:
parent
773e9e1c7e
commit
64203312ac
|
@ -83,6 +83,7 @@ public abstract class SemanticContext {
|
||||||
this.isCtxDependent = isCtxDependent;
|
this.isCtxDependent = isCtxDependent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean eval(Recognizer<?,?> parser, RuleContext outerContext) {
|
public boolean eval(Recognizer<?,?> parser, RuleContext outerContext) {
|
||||||
RuleContext localctx = isCtxDependent ? outerContext : null;
|
RuleContext localctx = isCtxDependent ? outerContext : null;
|
||||||
return parser.sempred(localctx, ruleIndex, predIndex);
|
return parser.sempred(localctx, ruleIndex, predIndex);
|
||||||
|
@ -90,7 +91,11 @@ public abstract class SemanticContext {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return ruleIndex + predIndex;
|
int hashCode = 1;
|
||||||
|
hashCode = 31 * hashCode + ruleIndex;
|
||||||
|
hashCode = 31 * hashCode + predIndex;
|
||||||
|
hashCode = 31 * hashCode + (isCtxDependent ? 1 : 0);
|
||||||
|
return hashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -103,6 +108,7 @@ public abstract class SemanticContext {
|
||||||
this.isCtxDependent == p.isCtxDependent;
|
this.isCtxDependent == p.isCtxDependent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "{"+ruleIndex+":"+predIndex+"}?";
|
return "{"+ruleIndex+":"+predIndex+"}?";
|
||||||
}
|
}
|
||||||
|
@ -131,6 +137,7 @@ public abstract class SemanticContext {
|
||||||
return opnds.hashCode();
|
return opnds.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean eval(Recognizer<?,?> parser, RuleContext outerContext) {
|
public boolean eval(Recognizer<?,?> parser, RuleContext outerContext) {
|
||||||
for (SemanticContext opnd : opnds) {
|
for (SemanticContext opnd : opnds) {
|
||||||
if ( !opnd.eval(parser, outerContext) ) return false;
|
if ( !opnd.eval(parser, outerContext) ) return false;
|
||||||
|
@ -138,6 +145,7 @@ public abstract class SemanticContext {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return Utils.join(opnds.iterator(), "&&");
|
return Utils.join(opnds.iterator(), "&&");
|
||||||
}
|
}
|
||||||
|
@ -166,6 +174,7 @@ public abstract class SemanticContext {
|
||||||
return opnds.hashCode() + 1; // differ from AND slightly
|
return opnds.hashCode() + 1; // differ from AND slightly
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean eval(Recognizer<?,?> parser, RuleContext outerContext) {
|
public boolean eval(Recognizer<?,?> parser, RuleContext outerContext) {
|
||||||
for (SemanticContext opnd : opnds) {
|
for (SemanticContext opnd : opnds) {
|
||||||
if ( opnd.eval(parser, outerContext) ) return true;
|
if ( opnd.eval(parser, outerContext) ) return true;
|
||||||
|
|
Loading…
Reference in New Issue