MCPcopy Create free account
hub / github.com/dmtcp/dmtcp / _IncludeState

Class _IncludeState

util/cpplint.py:686–848  ·  view source on GitHub ↗

Tracks line numbers for includes, and the order in which includes appear. include_list contains list of lists of (header, line number) pairs. It's a lists of lists rather than just one flat list to make it easier to update across preprocessor boundaries. Call CheckNextIncludeOrder() once f

Source from the content-addressed store, hash-verified

684
685
686class _IncludeState(object):
687 """Tracks line numbers for includes, and the order in which includes appear.
688
689 include_list contains list of lists of (header, line number) pairs.
690 It's a lists of lists rather than just one flat list to make it
691 easier to update across preprocessor boundaries.
692
693 Call CheckNextIncludeOrder() once for each header in the file, passing
694 in the type constants defined above. Calls in an illegal order will
695 raise an _IncludeError with an appropriate error message.
696
697 """
698 # self._section will move monotonically through this set. If it ever
699 # needs to move backwards, CheckNextIncludeOrder will raise an error.
700 _INITIAL_SECTION = 0
701 _MY_H_SECTION = 1
702 _C_SECTION = 2
703 _CPP_SECTION = 3
704 _OTHER_H_SECTION = 4
705
706 _TYPE_NAMES = {
707 _C_SYS_HEADER: 'C system header',
708 _CPP_SYS_HEADER: 'C++ system header',
709 _LIKELY_MY_HEADER: 'header this file implements',
710 _POSSIBLE_MY_HEADER: 'header this file may implement',
711 _OTHER_HEADER: 'other header',
712 }
713 _SECTION_NAMES = {
714 _INITIAL_SECTION: "... nothing. (This can't be an error.)",
715 _MY_H_SECTION: 'a header this file implements',
716 _C_SECTION: 'C system header',
717 _CPP_SECTION: 'C++ system header',
718 _OTHER_H_SECTION: 'other header',
719 }
720
721 def __init__(self):
722 self.include_list = [[]]
723 self.ResetSection('')
724
725 def FindHeader(self, header):
726 """Check if a header has already been included.
727
728 Args:
729 header: header to check.
730 Returns:
731 Line number of previous occurrence, or -1 if the header has not
732 been seen before.
733 """
734 for section_list in self.include_list:
735 for f in section_list:
736 if f[0] == header:
737 return f[1]
738 return -1
739
740 def ResetSection(self, directive):
741 """Reset section checking for preprocessor directive.
742
743 Args:

Callers 1

ProcessFileDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected