1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2 * Use of this file is governed by the BSD 3-clause license that
3 * can be found in the LICENSE.txt file in the project root.
6 #include "tree/ParseTree.h"
7 #include "tree/Trees.h"
8 #include "support/CPPUtils.h"
11 #include "XPathTokenElement.h"
13 using namespace antlr4;
14 using namespace antlr4::tree;
15 using namespace antlr4::tree::xpath;
17 XPathTokenElement::XPathTokenElement(const std::string &tokenName, size_t tokenType) : XPathElement(tokenName) {
18 _tokenType = tokenType;
21 std::vector<ParseTree *> XPathTokenElement::evaluate(ParseTree *t) {
22 // return all children of t that match nodeName
23 std::vector<ParseTree *> nodes;
24 for (auto *c : t->children) {
25 if (antlrcpp::is<TerminalNode *>(c)) {
26 TerminalNode *tnode = dynamic_cast<TerminalNode *>(c);
27 if ((tnode->getSymbol()->getType() == _tokenType && !_invert) || (tnode->getSymbol()->getType() != _tokenType && _invert)) {
28 nodes.push_back(tnode);