javacc-6.1.2.classes.templates.cpp.SimpleNodeImpl.template 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.
SimpleNode::SimpleNode(int i)
#if NODE_EXTENDS
: ${NODE_EXTENDS}(), parent(NULL), value(NULL)
#fi
{
id = i;
parser = NULL;
value = NULL;
}
SimpleNode::SimpleNode(${PARSER_NAME} *p, int i)
#if NODE_EXTENDS
: ${NODE_EXTENDS}(), parent(NULL), value(NULL)
#fi
{
id = i;
parser = p;
value = NULL;
}
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, int i) {
if (i >= children.size()) {
children.resize(i + 1, NULL);
}
children[i] = n;
}
Node *SimpleNode::jjtGetChild(int i) const {
return i < children.size() ? children[i] : NULL;
}
int SimpleNode::jjtGetNumChildren() const {
return children.size();
}
void SimpleNode::jjtSetValue(void * value) { this->value = value; }
void * SimpleNode::jjtGetValue() const { return value; }
#if TRACK_TOKENS
Token SimpleNode::jjtGetFirstToken() const { return firstToken; }
void SimpleNode::jjtSetFirstToken(Token token) { this->firstToken = token; }
Token SimpleNode::jjtGetLastToken() const { return lastToken; }
void SimpleNode::jjtSetLastToken(Token token) { this->lastToken = token; }
#fi
#if VISITOR
/** Accept the visitor. **/
${VISITOR_RETURN_TYPE} SimpleNode::jjtAccept(${PARSER_NAME}Visitor *visitor, ${VISITOR_DATA_TYPE:-void *} data) const
{
#if VISITOR_RETURN_TYPE_VOID
visitor->visit(this, data);
#else
return visitor->visit(this, data);
#fi
}
/** Accept the visitor. **/
void SimpleNode::childrenAccept(${PARSER_NAME}Visitor *visitor, ${VISITOR_DATA_TYPE:-void *} data) const {
for (int i = 0; i < children.size(); ++i) {
children[i]->jjtAccept(visitor, data);
}
}
#fi
/* 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. */
JAVACC_STRING_TYPE SimpleNode::toString() const { return jjtNodeName[id]; }
JAVACC_STRING_TYPE SimpleNode::toString(JAVACC_STRING_TYPE prefix) const { return prefix + toString(); }
static JAVACC_CHAR_TYPE space_char_arr_[] = { ' ', '\0' };
static JAVACC_CHAR_TYPE newline_char_arr_[] = { '\n', '\0' };
static JAVACC_STRING_TYPE space = space_char_arr_;
static JAVACC_STRING_TYPE newline = newline_char_arr_;
/* Override this method if you want to customize how the node dumps
out its children. */
void SimpleNode::dumpToBuffer(JAVACC_STRING_TYPE prefix, JAVACC_STRING_TYPE separator, JAVACC_STRING_TYPE *buffer) const {
buffer->append(toString(prefix));
buffer->append(separator);
for (int i = 0; i < children.size(); ++i) {
SimpleNode *n = (SimpleNode*)children[i];
if (n != NULL) {
n->dumpToBuffer(prefix + space, separator, buffer);
}
}
}
void SimpleNode::dump(JAVACC_STRING_TYPE prefix) const {
JAVACC_STRING_TYPE *buffer = new JAVACC_STRING_TYPE();
dumpToBuffer(prefix, newline, buffer);
for (int i = 0; i < buffer->size(); i++) {
printf("%c", (*buffer)[i]);
}
delete buffer;
}
SimpleNode::~SimpleNode() {
for (int i = 0; i < children.size(); ++i) {
delete children[i];
}
}