| 1736 | } |
| 1737 | |
| 1738 | void SymbolScanner::checkAnnotationBeforeAdding(AstNode *annotation, Symbol *symbol) |
| 1739 | { |
| 1740 | AstNode *annotation_name = annotation->getChild(1); |
| 1741 | Value *annValue = getAnnotationValue(annotation); |
| 1742 | |
| 1743 | if (annotation_name->getTokenString().compare(LENGTH_ANNOTATION) == 0) |
| 1744 | { |
| 1745 | StructMember *structMember = dynamic_cast<StructMember *>(symbol); |
| 1746 | if (structMember) |
| 1747 | { |
| 1748 | DataType *trueDataType = structMember->getDataType()->getTrueDataType(); |
| 1749 | if (trueDataType && (!trueDataType->isList() && !trueDataType->isBinary())) |
| 1750 | { |
| 1751 | throw semantic_error( |
| 1752 | format_string("line %d: Length annotation can only be applied to list or binary types", |
| 1753 | annotation_name->getToken().getFirstLine())); |
| 1754 | } |
| 1755 | |
| 1756 | // Check @length annotation's value. |
| 1757 | if (!annValue) |
| 1758 | { |
| 1759 | throw semantic_error(format_string("line %d: Length annotation must name a valid parameter or member", |
| 1760 | annotation_name->getToken().getFirstLine())); |
| 1761 | } |
| 1762 | } |
| 1763 | } |
| 1764 | else if (annotation_name->getTokenString().compare(MAX_LENGTH_ANNOTATION) == 0) |
| 1765 | { |
| 1766 | StructMember *structMember = dynamic_cast<StructMember *>(symbol); |
| 1767 | if (structMember) |
| 1768 | { |
| 1769 | DataType *trueDataType = structMember->getDataType()->getTrueDataType(); |
| 1770 | if (trueDataType && (!trueDataType->isList() && !trueDataType->isBinary() && !trueDataType->isString())) |
| 1771 | { |
| 1772 | throw semantic_error( |
| 1773 | format_string("line %d: Max_length annotation can only be applied to list, binary, or string types", |
| 1774 | annotation_name->getToken().getFirstLine())); |
| 1775 | } |
| 1776 | |
| 1777 | // Check @length annotation's value. |
| 1778 | if (!annValue) |
| 1779 | { |
| 1780 | throw semantic_error( |
| 1781 | format_string("line %d: Max_length annotation must name a valid parameter or member", |
| 1782 | annotation_name->getToken().getFirstLine())); |
| 1783 | } |
| 1784 | } |
| 1785 | } |
| 1786 | } |
| 1787 | |
| 1788 | void SymbolScanner::scanStructForAnnotations() |
| 1789 | { |
nothing calls this directly
no test coverage detected