std::string MySQLRecognitionBase::dumpTree(pANTLR3_UINT8 *tokenNames, pANTLR3_BASE_TREE tree, const std::string &indentation) { std::string result; ANTLR3_UINT32 char_pos = tree->getCharPositionInLine(tree); ANTLR3_UINT32 line = tree->getLine(tree); pANTLR3_STRING token_text = tree->getText(tree); pANTLR3_COMMON_TOKEN token = tree->getToken(tree); const char* utf8 = (const char*)token_text->chars; if (token != NULL) { ANTLR3_UINT32 token_type = token->getType(token); pANTLR3_UINT8 token_name; if (token_type == EOF) token_name = (pANTLR3_UINT8)"EOF"; else token_name = tokenNames[token_type]; #ifdef ANTLR3_USE_64BIT result = base::strfmt("%s(line: %i, offset: %i, length: %" PRId64 ", index: %" PRId64 ", %s[%i]) %s\n", indentation.c_str(), line, char_pos, token->stop - token->start + 1, token->index, token_name, token_type, utf8); #else result = base::strfmt("%s(line: %i, offset: %i, length: %i, index: %i, %s[%i]) %s\n", indentation.c_str(), line, char_pos, token->stop - token->start + 1, token->index, token_name, token_type, utf8); #endif } else { result = base::strfmt("%s(line: %i, offset: %i, nil) %s\n", indentation.c_str(), line, char_pos, utf8); } for (ANTLR3_UINT32 index = 0; index < tree->getChildCount(tree); index++) { pANTLR3_BASE_TREE child = (pANTLR3_BASE_TREE)tree->getChild(tree, index); std::string child_text = dumpTree(tokenNames, child, indentation + "\t"); result += child_text; } return result; }
ASTNode::ASTNode(const pANTLR3_BASE_TREE node) { m_LineNumber = node->getLine(node); m_CharPosition = node->getCharPositionInLine(node); pANTLR3_BASE_TREE n = node; while ((n != NULL) && (n->u == NULL)) { if (n->u != NULL) { m_FileName = (wchar_t*) n->u; node->u = n->u; break; } else { n = n->getParent(n); } } }