IntegerLiteralValueDef::IntegerLiteralValueDef(const pANTLR3_BASE_TREE node) : LiteralValueDef(INTEGER_LITERAL, node) { assert(node->getType(node) == N_INT_LITERAL); assert(node->getChildCount(node) == 1); pANTLR3_BASE_TREE n = (pANTLR3_BASE_TREE) node->getChild(node, 0); assert(n->getType(n) == INTL); wchar_t* szStr = (wchar_t*) n->getText(n)->chars; int value; try { value = boost::lexical_cast<int, wchar_t*>(szStr); } catch (const std::exception&) { boost::wformat f(L"Invalid integer value: %1% at line %2%"); f % szStr % node->getLine(node); ParserException e(f.str()); throw e; } m_IntValue = value; }
ActualParamDef::ActualParamDef(const pANTLR3_BASE_TREE node) : ASTNode(node) { assert(node->getType(node) == N_ACTUAL_PARAM); assert(node->getChildCount(node) == 2); pANTLR3_BASE_TREE n; { // param name n = (pANTLR3_BASE_TREE) node->getChild(node, 0); assert(n->getType(n) == N_PARAM_NAME); assert(n->getChildCount(n) == 1); n = (pANTLR3_BASE_TREE) n->getChild(n, 0); m_ParamName = (wchar_t*) n->getText(n)->chars; } { // value n = (pANTLR3_BASE_TREE) node->getChild(node, 1); assert(n->getType(n) == N_VALUE); createValueDef(n, m_pValue); } }
ArrayInitValueDef::ArrayInitValueDef(const pANTLR3_BASE_TREE node) : ValueDef(ARRAY_INIT, node) { assert(node->getType(node) == N_ARRAY_INIT_VAL); assert(node->getChildCount(node) == 2); pANTLR3_BASE_TREE n, c; { // type n = (pANTLR3_BASE_TREE) node->getChild(node, 0); assert(n->getType(n) == N_ARRAY_TYPE); m_pDeclaredType = boost::shared_ptr<Type>(static_cast<Type*>(new ArrayType(n))); } { // array values n = (pANTLR3_BASE_TREE) node->getChild(node, 1); assert(n->getType(n) == N_ARRAY_VALUES); m_Values.clear(); int childCount = n->getChildCount(n); for (int i = 0; i < childCount; i++) { c = (pANTLR3_BASE_TREE) n->getChild(n, i); boost::shared_ptr<ValueDef> pValueDef; createValueDef(c, pValueDef); m_Values.push_back(pValueDef); } } }
static void toStringWork (pANTLR3_TREE_NODE_STREAM tns, pANTLR3_BASE_TREE p, pANTLR3_BASE_TREE stop, pANTLR3_STRING buf) { ANTLR3_UINT32 n; ANTLR3_UINT32 c; if (!p->isNilNode(p) ) { pANTLR3_STRING text; text = p->toString(p); if (text == NULL) { text = tns->ctns->stringFactory->newRaw(tns->ctns->stringFactory); text->addc (text, ' '); text->addi (text, p->getType(p)); } buf->appendS(buf, text); } if (p == stop) { return; /* Finished */ } n = p->getChildCount(p); if (n > 0 && ! p->isNilNode(p) ) { buf->addc (buf, ' '); buf->addi (buf, ANTLR3_TOKEN_DOWN); } for (c = 0; c<n ; c++) { pANTLR3_BASE_TREE child; child = p->getChild(p, c); tns->toStringWork(tns, child, stop, buf); } if (n > 0 && ! p->isNilNode(p) ) { buf->addc (buf, ' '); buf->addi (buf, ANTLR3_TOKEN_UP); } }
static pANTLR3_BASE_TREE getFirstChildWithType (pANTLR3_BASE_TREE tree, ANTLR3_UINT32 type) { ANTLR3_UINT32 i; ANTLR3_UINT32 cs; pANTLR3_BASE_TREE t; if (tree->children != NULL) { cs = tree->children->size(tree->children); for (i = 0; i < cs; i++) { t = (pANTLR3_BASE_TREE) (tree->children->get(tree->children, i)); if (tree->getType(t) == type) { return (pANTLR3_BASE_TREE)t; } } } return NULL; }
ObjectInitValueDef::ObjectInitValueDef(const pANTLR3_BASE_TREE node) : ValueDef(OBJECT_INIT, node) { assert(node->getType(node) == N_OBJECT_INIT_VAL); assert(node->getChildCount(node) == 2); pANTLR3_BASE_TREE n, c; { // class name n = (pANTLR3_BASE_TREE) node->getChild(node, 0); assert(n->getType(n) == N_CLASS_NAME); assert(n->getChildCount(n) == 1); n = (pANTLR3_BASE_TREE) n->getChild(n, 0); assert(n->getType(n) == ID); wchar_t* szClassName = (wchar_t*) n->getText(n)->chars; m_ClassName = szClassName; } { m_ActualParamsMap.clear(); // actual params n = (pANTLR3_BASE_TREE) node->getChild(node, 1); assert(n->getType(n) == N_ACTUAL_PARAMS); int childCount = n->getChildCount(n); for (int i = 0; i < childCount; i++) { c = (pANTLR3_BASE_TREE) n->getChild(n, i); assert(c->getType(c) == N_ACTUAL_PARAM); ActualParamDefPtr pActualParamDef(new ActualParamDef(c)); m_ActualParamsMap[pActualParamDef->getParamName()] = pActualParamDef; } } }
static ANTLR3_UINT32 getType (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t) { return t->getType(t); }
StringLiteralValueDef::StringLiteralValueDef(const pANTLR3_BASE_TREE node) : LiteralValueDef(STRING_LITERAL, node) { assert(node->getType(node) == N_STRING_LITERAL); assert(node->getChildCount(node) == 1); pANTLR3_BASE_TREE n, c; n = (pANTLR3_BASE_TREE) node->getChild(node, 0); assert(n->getType(n) == STRINGL); wchar_t* szStr = (wchar_t*) n->getText(n)->chars; std::wstringbuf strBuff; int state = START_STATE; for (wchar_t* pCurr = szStr; *pCurr != L'\0'; pCurr++) { wchar_t curr = *pCurr; switch (state) { case START_STATE: assert(curr == L'"'); state = NO_ESC_STATE; break; case NO_ESC_STATE: if (curr == L'\\') { state = ESC_BEGIN_STATE; } else if (curr == L'"') { state = END_STATE; } else { strBuff.sputc(curr); } break; case ESC_BEGIN_STATE: switch (curr) { case L'b': strBuff.sputc(L'\b'); state = NO_ESC_STATE; break; case L't': strBuff.sputc(L'\t'); state = NO_ESC_STATE; break; case L'n': strBuff.sputc(L'\n'); state = NO_ESC_STATE; break; case L'f': strBuff.sputc(L'\f'); state = NO_ESC_STATE; break; case L'r': strBuff.sputc(L'\r'); state = NO_ESC_STATE; break; case L'"': strBuff.sputc(L'\"'); state = NO_ESC_STATE; break; case L'\'': strBuff.sputc(L'\''); state = NO_ESC_STATE; break; case L'\\': strBuff.sputc(L'\\'); state = NO_ESC_STATE; break; default: boost::wformat f(L"Unknown escape sequence \\%1% at line %2%"); f % curr % node->getLine(node); ParserException e(f.str()); throw e; } break; case END_STATE: assert(false); break; default: assert(false); break; } } assert(state == END_STATE); m_StringValue = strBuff.str(); }