| 1786 | } |
| 1787 | |
| 1788 | void SymbolScanner::scanStructForAnnotations() |
| 1789 | { |
| 1790 | assert(m_currentStruct); |
| 1791 | |
| 1792 | // go trough all structure members |
| 1793 | for (StructMember *structMember : m_currentStruct->getMembers()) |
| 1794 | { |
| 1795 | DataType *memberType = structMember->getDataType()->getTrueDataType(); |
| 1796 | /* Check non-encapsulated discriminated unions. */ |
| 1797 | if (memberType->isUnion()) |
| 1798 | { |
| 1799 | UnionType *unionType = dynamic_cast<UnionType *>(structMember->getDataType()); |
| 1800 | assert(unionType); |
| 1801 | Symbol *disSymbol; |
| 1802 | if (unionType->isNonEncapsulatedUnion()) |
| 1803 | { |
| 1804 | string discrimintorName = |
| 1805 | structMember->getAnnStringValue(DISCRIMINATOR_ANNOTATION, Annotation::program_lang_t::kAll); |
| 1806 | if (discrimintorName.empty()) |
| 1807 | { |
| 1808 | throw syntax_error(format_string("Missing discriminator for union variable %s on line %d", |
| 1809 | structMember->getName().c_str(), structMember->getFirstLine())); |
| 1810 | } |
| 1811 | |
| 1812 | // search in structure scope for member referenced with annotation |
| 1813 | disSymbol = m_currentStruct->getScope().getSymbol(discrimintorName, false); |
| 1814 | if (!disSymbol) |
| 1815 | { |
| 1816 | disSymbol = m_globals->getSymbol(discrimintorName, false); |
| 1817 | } |
| 1818 | if (!disSymbol) |
| 1819 | { |
| 1820 | throw syntax_error( |
| 1821 | format_string("Value defined in annotation discriminator used for union " |
| 1822 | "variable %s on line %d has to point to variable in same/global scope.", |
| 1823 | structMember->getName().c_str(), structMember->getFirstLine())); |
| 1824 | } |
| 1825 | } |
| 1826 | else |
| 1827 | { |
| 1828 | disSymbol = m_currentStruct->getScope().getSymbol(unionType->getDiscriminatorName(), false); |
| 1829 | if (!disSymbol) |
| 1830 | { |
| 1831 | throw syntax_error( |
| 1832 | format_string("Discriminator used for union variable %s on line %d has to point " |
| 1833 | "to variable in same scope.", |
| 1834 | structMember->getName().c_str(), structMember->getFirstLine())); |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | // check discriminator data type |
| 1839 | DataType *disType; |
| 1840 | if (StructMember *disStructMember = dynamic_cast<StructMember *>(disSymbol)) |
| 1841 | { |
| 1842 | disType = disStructMember->getDataType()->getTrueDataType(); |
| 1843 | } |
| 1844 | else |
| 1845 | { |
nothing calls this directly
no test coverage detected