Automatically reduce SemanticContext.AND/SemanticContext.OR with a single operand to the operand itself

This commit is contained in:
Sam Harwell 2012-12-12 09:35:54 -06:00
parent e5e4402ea9
commit 9b75ea79f9
1 changed files with 12 additions and 2 deletions

View File

@ -197,7 +197,12 @@ public abstract class SemanticContext {
public static SemanticContext and(SemanticContext a, SemanticContext b) {
if ( a == null || a == NONE ) return b;
if ( b == null || b == NONE ) return a;
return new AND(a, b);
AND result = new AND(a, b);
if (result.opnds.length == 1) {
return result.opnds[0];
}
return result;
}
/**
@ -208,6 +213,11 @@ public abstract class SemanticContext {
if ( a == null ) return b;
if ( b == null ) return a;
if ( a == NONE || b == NONE ) return NONE;
return new OR(a, b);
OR result = new OR(a, b);
if (result.opnds.length == 1) {
return result.opnds[0];
}
return result;
}
}