javacc-7.0.3.bin.templates.cpp.SimpleNode.cc.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.
\#include
\#include "SimpleNode.h"
#if VISITOR
\#include "${PARSER_NAME}Visitor.h"
#fi
#if NAMESPACE
namespace ${NAMESPACE_OPEN}
#fi
SimpleNode::SimpleNode(int id) :
id(id)
#if NODE_EXTENDS
, ${NODE_EXTENDS}()
#fi
{
}
SimpleNode::SimpleNode(${PARSER_NAME} *parser, int id) :
parser(parser), id(id)
#if NODE_EXTENDS
, ${NODE_EXTENDS}()
#fi
{
}
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;
}
#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
${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
}
void SimpleNode::jjtChildrenAccept(${PARSER_NAME}Visitor *visitor, ${VISITOR_DATA_TYPE:-void *} data) const {
for (size_t i = 0; i < children.size(); ++i) {
children[i]->jjtAccept(visitor, data);
}
}
void SimpleNode::jjtChildAccept(int childNo, ${PARSER_NAME}Visitor *visitor, ${VISITOR_DATA_TYPE:-void *} data) const {
if (0 <= childNo && childNo < children.size())
children[childNo]->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. */
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];
}
}
#if NAMESPACE
${NAMESPACE_CLOSE}
#fi
© 2015 - 2024 Weber Informatics LLC | Privacy Policy