MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / getElementByDesignator

Function getElementByDesignator

addons/misra_9.py:525–559  ·  view source on GitHub ↗
(ed, token)

Source from the content-addressed store, hash-verified

523
524
525def getElementByDesignator(ed, token):
526 if not token.str in [ '.', '[' ]:
527 return None
528
529 while token.str in [ '.', '[' ]:
530 token = token.astOperand1
531
532 while ed and not token.isAssignmentOp:
533 token = token.astParent
534
535 if token.str == '[':
536 if not ed.isArray:
537 ed.markStuctureViolation(token)
538
539 chIndex = -1
540 if token.astOperand2 is not None:
541 chIndex = token.astOperand2.getKnownIntValue()
542 elif token.astOperand1 is not None:
543 chIndex = token.astOperand1.getKnownIntValue()
544
545 ed = ed.getChildByIndex(chIndex) if chIndex is not None else None
546
547 elif token.str == '.':
548 if not ed.isRecord:
549 ed.markStuctureViolation(token)
550
551 name = ""
552 if token.astOperand2 is not None:
553 name = token.astOperand2.str
554 elif token.astOperand1 is not None:
555 name = token.astOperand1.str
556
557 ed = ed.getChildByName(name)
558
559 return ed

Callers 1

parseInitializerMethod · 0.85

Calls 4

markStuctureViolationMethod · 0.80
getKnownIntValueMethod · 0.80
getChildByIndexMethod · 0.80
getChildByNameMethod · 0.80

Tested by

no test coverage detected