| 1568 | } |
| 1569 | |
| 1570 | Value *SymbolScanner::getValueFromSymbol(const Token &tok) |
| 1571 | { |
| 1572 | if (tok.getValue() != nullptr) |
| 1573 | { |
| 1574 | string name = tok.getStringValue(); |
| 1575 | Symbol *sym = m_globals->getSymbol(name); |
| 1576 | if (nullptr != sym) |
| 1577 | { |
| 1578 | Value *newVal; |
| 1579 | if (sym->isConstSymbol()) |
| 1580 | { |
| 1581 | ConstType *constVar = dynamic_cast<ConstType *>(sym); |
| 1582 | assert(constVar); |
| 1583 | newVal = constVar->getValue()->clone(); |
| 1584 | } |
| 1585 | else if (sym->isEnumMemberSymbol()) |
| 1586 | { |
| 1587 | EnumMember *enumVar = dynamic_cast<EnumMember *>(sym); |
| 1588 | assert(enumVar); |
| 1589 | newVal = new IntegerValue(enumVar->getValue()); |
| 1590 | } |
| 1591 | else |
| 1592 | { |
| 1593 | throw semantic_error(format_string("line %d: Cannot get value from symbol type: %s.\n", |
| 1594 | tok.getFirstLine(), sym->getDescription().c_str())); |
| 1595 | } |
| 1596 | |
| 1597 | return newVal; |
| 1598 | } |
| 1599 | |
| 1600 | throw syntax_error(format_string("line %d: Symbol %s is not defined.\n", tok.getFirstLine(), name.c_str())); |
| 1601 | } |
| 1602 | |
| 1603 | throw syntax_error(format_string("line %d: cannot get token value.\n", tok.getFirstLine())); |
| 1604 | } |
| 1605 | |
| 1606 | uint64_t SymbolScanner::getIntExprValue(const AstNode *exprNode) |
| 1607 | { |
nothing calls this directly
no test coverage detected