javacc-7.0.1.examples.JJTreeExamples.cpp.eg2.SimpleNode.cc Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javacc Show documentation
Show all versions of javacc Show documentation
JavaCC is a parser/scanner generator for Java.
/* Generated By:JJTree: Do not edit this line. SimpleNode.cc Version 7.0 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=false,TRACK_TOKENS=false,NODE_PREFIX=AST,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
#include
#include "SimpleNode.h"
namespace EG2 {
SimpleNode::SimpleNode(int id) :
id(id)
{
}
SimpleNode::SimpleNode(Parser *parser, int id) :
parser(parser), id(id)
{
}
void SimpleNode::jjtOpen() const {
}
void SimpleNode::jjtClose() const {
}
void SimpleNode::jjtSetParent(Node *n) {
parent = n;
}
Node *SimpleNode::jjtGetParent() const {
return parent;
}
void SimpleNode::jjtAddChild(Node *n, size_t i) {
if (i >= children.size()) {
children.resize(i + 1, nullptr);
}
children[i] = n;
}
Node *SimpleNode::jjtGetChild(size_t i) const {
return i < children.size() ? children[i] : nullptr;
}
size_t SimpleNode::jjtGetNumChildren() const {
return children.size();
}
void SimpleNode::jjtSetValue(void * value) {
this->value = value;
}
void * SimpleNode::jjtGetValue() const {
return value;
}
/* You can override these two methods in subclasses of SimpleNode to
customize the way the node appears when the tree is dumped. If
your output uses more than one line you should override
toString(string), otherwise overriding toString() is probably all
you need to do. */
JJString SimpleNode::toString() const { return jjtNodeName[id]; }
JJString SimpleNode::toString(const JJString& prefix) const { return prefix + toString(); }
static JJChar space_char_arr_[] = { ' ', '\0' };
static JJChar newline_char_arr_[] = { '\n', '\0' };
static JJString space = space_char_arr_;
static JJString newline = newline_char_arr_;
/* Override this method if you want to customize how the node dumps
out its children. */
void SimpleNode::dumpToBuffer(const JJString& prefix, const JJString& separator, JJString *buffer) const {
buffer->append(toString(prefix));
buffer->append(separator);
for (size_t i = 0; i < children.size(); ++i) {
SimpleNode *n = (SimpleNode*)children[i];
if (n != nullptr) {
n->dumpToBuffer(prefix + space, separator, buffer);
}
}
}
void SimpleNode::dump(const JJString& prefix) const {
JJString *buffer = new JJString();
dumpToBuffer(prefix, newline, buffer);
for (size_t i = 0; i < buffer->size(); i++) {
printf("%c", (*buffer)[i]);
}
delete buffer;
}
SimpleNode::~SimpleNode() {
for (size_t i = 0; i < children.size(); ++i) {
delete children[i];
}
}
}
/* JavaCC - OriginalChecksum=f4d9976274bb092275fb0565bf4a4e8d (do not edit this line) */