MCPcopy Create free account
hub / github.com/EmbeddedRPC/erpc / scanStructForAnnotations

Method scanStructForAnnotations

erpcgen/src/SymbolScanner.cpp:1788–1861  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1786}
1787
1788void 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 {

Callers

nothing calls this directly

Calls 14

syntax_errorClass · 0.85
format_stringFunction · 0.85
getTrueDataTypeMethod · 0.80
isUnionMethod · 0.80
getSymbolMethod · 0.80
getDiscriminatorNameMethod · 0.80
isEnumMethod · 0.80
getDataTypeMethod · 0.45
getAnnStringValueMethod · 0.45
emptyMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected