Java Code Examples for antlr.collections.AST#equals()
The following examples show how to use
antlr.collections.AST#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseAST.java From dacapobench with Apache License 2.0 | 5 votes |
/** Is t an exact structural and equals() match of this tree. The * 'this' reference is considered the start of a sibling list. */ public boolean equalsList(AST t) { AST sibling; // the empty tree is not a match of any non-null tree. if (t == null) { return false; } // Otherwise, start walking sibling lists. First mismatch, return false. for (sibling = this; sibling != null && t != null; sibling = sibling.getNextSibling(), t = t.getNextSibling()) { // as a quick optimization, check roots first. if (!sibling.equals(t)) { return false; } // if roots match, do full list match test on children. if (sibling.getFirstChild() != null) { if (!sibling.getFirstChild().equalsList(t.getFirstChild())) { return false; } } // sibling has no kids, make sure t doesn't either else if (t.getFirstChild() != null) { return false; } } if (sibling == null && t == null) { return true; } // one sibling list has more than the other return false; }
Example 2
Source File: BaseAST.java From dacapobench with Apache License 2.0 | 5 votes |
/** Is 'sub' a subtree of this list? * The siblings of the root are NOT ignored. */ public boolean equalsListPartial(AST sub) { AST sibling; // the empty tree is always a subset of any tree. if (sub == null) { return true; } // Otherwise, start walking sibling lists. First mismatch, return false. for (sibling = this; sibling != null && sub != null; sibling = sibling.getNextSibling(), sub = sub.getNextSibling()) { // as a quick optimization, check roots first. if (!sibling.equals(sub)) return false; // if roots match, do partial list match test on children. if (sibling.getFirstChild() != null) { if (!sibling.getFirstChild().equalsListPartial(sub.getFirstChild())) return false; } } if (sibling == null && sub != null) { // nothing left to match in this tree, but subtree has more return false; } // either both are null or sibling has more, but subtree doesn't return true; }