| 3557 | } |
| 3558 | |
| 3559 | void CGenerator::checkIfAnnValueIsIntNumberOrIntType(Annotation *ann, StructType *currentStructType) |
| 3560 | { |
| 3561 | // skip if value is integer number |
| 3562 | if (ann->getValueObject()->getType() != kIntegerValue) |
| 3563 | { |
| 3564 | string annName = ann->getName(); |
| 3565 | int annNameFirstLine = ann->getLocation().m_firstLine; |
| 3566 | string annValue = ann->getValueObject()->toString(); |
| 3567 | |
| 3568 | DataType *trueDataType = nullptr; |
| 3569 | |
| 3570 | // search in structure scope for member referenced with annotation |
| 3571 | for (StructMember *structMember : currentStructType->getMembers()) |
| 3572 | { |
| 3573 | if (structMember->getName().compare(annValue) == 0) |
| 3574 | { |
| 3575 | trueDataType = structMember->getDataType()->getTrueDataType(); |
| 3576 | break; |
| 3577 | } |
| 3578 | } |
| 3579 | |
| 3580 | if (!trueDataType) |
| 3581 | { |
| 3582 | // search in global scope for member referenced with annotation |
| 3583 | Symbol *symbolConst = m_globals->getSymbol(annValue); |
| 3584 | if (symbolConst) |
| 3585 | { |
| 3586 | ConstType *constVar = dynamic_cast<ConstType *>(symbolConst); |
| 3587 | if (constVar) |
| 3588 | { |
| 3589 | trueDataType = constVar->getDataType(); |
| 3590 | } |
| 3591 | } |
| 3592 | } |
| 3593 | |
| 3594 | if (trueDataType) |
| 3595 | { |
| 3596 | // check if data type is integer type |
| 3597 | if (trueDataType->isScalar()) |
| 3598 | { |
| 3599 | BuiltinType *builtinType = dynamic_cast<BuiltinType *>(trueDataType); |
| 3600 | if (builtinType && builtinType->isInt()) |
| 3601 | { |
| 3602 | return; |
| 3603 | } |
| 3604 | } |
| 3605 | |
| 3606 | throw semantic_error(format_string( |
| 3607 | "line %d: Annotation %s contains reference to non-integer parameter or member %s declared on line %d.", |
| 3608 | annNameFirstLine, annName.c_str(), annValue.c_str(), trueDataType->getLocation().m_firstLine)); |
| 3609 | } |
| 3610 | else |
| 3611 | { |
| 3612 | throw semantic_error(format_string("line %d: The parameter or member named by a %s annotation must exist.", |
| 3613 | annNameFirstLine, annName.c_str())); |
| 3614 | } |
| 3615 | } |
| 3616 | } |
nothing calls this directly
no test coverage detected