| 1604 | } |
| 1605 | |
| 1606 | uint64_t SymbolScanner::getIntExprValue(const AstNode *exprNode) |
| 1607 | { |
| 1608 | /* Check that this node is really an expr. */ |
| 1609 | const Token &tok = exprNode->getToken(); |
| 1610 | assert_throw_internal((tok.getToken() == TOK_EXPR), "node expected to be an expr is not"); |
| 1611 | |
| 1612 | /* Get the expr's value child node. */ |
| 1613 | AstNode *valueNode = const_cast<AstNode *>(exprNode)->getChild(0); |
| 1614 | Token &tok2 = valueNode->getToken(); |
| 1615 | |
| 1616 | /* If token is not an identifier, it must be either a binary expression |
| 1617 | that simplifies to an int literal or an int literal */ |
| 1618 | if (tok2.isIdentifierTok()) |
| 1619 | { |
| 1620 | Value *val = getValueFromSymbol(tok2); |
| 1621 | if (val == nullptr || kIntegerValue != val->getType()) |
| 1622 | { |
| 1623 | if (val != nullptr) |
| 1624 | { |
| 1625 | delete val; |
| 1626 | } |
| 1627 | throw semantic_error(format_string("line %d: expected integer expression", tok2.getFirstLine())); |
| 1628 | } |
| 1629 | assert(nullptr != dynamic_cast<IntegerValue *>(val)); |
| 1630 | uint64_t result = dynamic_cast<IntegerValue *>(val)->getValue(); |
| 1631 | delete val; |
| 1632 | return result; |
| 1633 | } |
| 1634 | /* If it is a binary expression, simplify expression and get the value from |
| 1635 | the re-written token. */ |
| 1636 | else if (tok2.isBinaryOp()) |
| 1637 | { |
| 1638 | walk(valueNode); |
| 1639 | } |
| 1640 | Token &valueToken = const_cast<AstNode *>(exprNode)->getChild(0)->getToken(); |
| 1641 | if (valueToken.getToken() != TOK_INT_LITERAL) |
| 1642 | { |
| 1643 | throw semantic_error(format_string("line %d: expected integer expression", tok2.getFirstLine())); |
| 1644 | } |
| 1645 | |
| 1646 | return valueToken.getIntValue(); |
| 1647 | } |
| 1648 | |
| 1649 | void SymbolScanner::addAnnotations(AstNode *childNode, Symbol *symbol) |
| 1650 | { |
nothing calls this directly
no test coverage detected