MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / _IncludeState

Class _IncludeState

Tools/cpplint.py:685–847  ·  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

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

Callers 1

ProcessFileDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected