@@ -704,14 +704,14 @@ def RunCode(env, code_node, output):
704
704
RunAtomicCode (env , atomic_code , output )
705
705
706
706
707
- def IsComment (cur_line ):
707
+ def IsSingleLineComment (cur_line ):
708
708
return '//' in cur_line
709
709
710
710
711
- def IsInPreprocessorDirevative (prev_lines , cur_line ):
711
+ def IsInPreprocessorDirective (prev_lines , cur_line ):
712
712
if cur_line .lstrip ().startswith ('#' ):
713
713
return True
714
- return prev_lines != [] and prev_lines [- 1 ].endswith ('\\ ' )
714
+ return prev_lines and prev_lines [- 1 ].endswith ('\\ ' )
715
715
716
716
717
717
def WrapComment (line , output ):
@@ -768,37 +768,45 @@ def WrapCode(line, line_concat, output):
768
768
output .append (prefix + cur_line .strip ())
769
769
770
770
771
- def WrapPreprocessorDirevative (line , output ):
771
+ def WrapPreprocessorDirective (line , output ):
772
772
WrapCode (line , ' \\ ' , output )
773
773
774
774
775
775
def WrapPlainCode (line , output ):
776
776
WrapCode (line , '' , output )
777
777
778
778
779
- def IsHeaderGuardOrInclude (line ):
779
+ def IsMultiLineIWYUPragma (line ):
780
+ return re .search (r'/\* IWYU pragma: ' , line )
781
+
782
+
783
+ def IsHeaderGuardIncludeOrOneLineIWYUPragma (line ):
780
784
return (re .match (r'^#(ifndef|define|endif\s*//)\s*[\w_]+\s*$' , line ) or
781
- re .match (r'^#include\s' , line ))
785
+ re .match (r'^#include\s' , line ) or
786
+ # Don't break IWYU pragmas, either; that causes iwyu.py problems.
787
+ re .search (r'// IWYU pragma: ' , line ))
782
788
783
789
784
790
def WrapLongLine (line , output ):
785
791
line = line .rstrip ()
786
792
if len (line ) <= 80 :
787
793
output .append (line )
788
- elif IsComment (line ):
789
- if IsHeaderGuardOrInclude (line ):
790
- # The style guide made an exception to allow long header guard lines
791
- # and includes .
794
+ elif IsSingleLineComment (line ):
795
+ if IsHeaderGuardIncludeOrOneLineIWYUPragma (line ):
796
+ # The style guide made an exception to allow long header guard lines,
797
+ # includes and IWYU pragmas .
792
798
output .append (line )
793
799
else :
794
800
WrapComment (line , output )
795
- elif IsInPreprocessorDirevative (output , line ):
796
- if IsHeaderGuardOrInclude (line ):
797
- # The style guide made an exception to allow long header guard lines
798
- # and includes .
801
+ elif IsInPreprocessorDirective (output , line ):
802
+ if IsHeaderGuardIncludeOrOneLineIWYUPragma (line ):
803
+ # The style guide made an exception to allow long header guard lines,
804
+ # includes and IWYU pragmas .
799
805
output .append (line )
800
806
else :
801
- WrapPreprocessorDirevative (line , output )
807
+ WrapPreprocessorDirective (line , output )
808
+ elif IsMultiLineIWYUPragma (line ):
809
+ output .append (line )
802
810
else :
803
811
WrapPlainCode (line , output )
804
812
0 commit comments