@@ -422,10 +422,10 @@ private final class BoxedTable {
422
422
}
423
423
}
424
424
425
- /// Check the input to FileCheck provided in the \p Buffer against the \p
426
- /// CheckStrings read from the check file.
425
+ /// Check the input to FileCheck provided in the buffer against the check
426
+ /// strings read from the check file.
427
427
///
428
- /// Returns false if the input fails to satisfy the checks.
428
+ /// Returns ` false` if the input fails to satisfy the checks.
429
429
private func check( input b : String , against checkStrings : [ CheckString ] ) -> Bool {
430
430
var buffer = b
431
431
var failedChecks = false
@@ -448,13 +448,14 @@ private func check(input b : String, against checkStrings : [CheckString]) -> Bo
448
448
}
449
449
450
450
// Scan to next CHECK-LABEL match, ignoring CHECK-NOT and CHECK-DAG
451
- guard let ( matchLabelPos , matchLabelLen ) = checkStr. check ( buffer, true , variableTable) else {
451
+ guard let range = checkStr. check ( buffer, true , variableTable) else {
452
452
// Immediately bail of CHECK-LABEL fails, nothing else we can do.
453
453
return false
454
454
}
455
455
456
- checkRegion = buffer. substring ( to: buffer. index ( buffer. startIndex, offsetBy: matchLabelPos + matchLabelLen) )
457
- buffer = buffer. substring ( from: buffer. index ( buffer. startIndex, offsetBy: matchLabelPos + matchLabelLen) )
456
+
457
+ checkRegion = buffer. substring ( to: buffer. index ( buffer. startIndex, offsetBy: NSMaxRange ( range) ) )
458
+ buffer = buffer. substring ( from: buffer. index ( buffer. startIndex, offsetBy: NSMaxRange ( range) ) )
458
459
j += 1
459
460
}
460
461
@@ -463,13 +464,13 @@ private func check(input b : String, against checkStrings : [CheckString]) -> Bo
463
464
464
465
// Check each string within the scanned region, including a second check
465
466
// of any final CHECK-LABEL (to verify CHECK-NOT and CHECK-DAG)
466
- guard let ( matchPos , matchLen ) = checkStrings [ i] . check ( checkRegion, false , variableTable) else {
467
+ guard let range = checkStrings [ i] . check ( checkRegion, false , variableTable) else {
467
468
failedChecks = true
468
469
i = j
469
470
break
470
471
}
471
472
472
- checkRegion = checkRegion. substring ( from: checkRegion. index ( checkRegion. startIndex, offsetBy: matchPos + matchLen ) )
473
+ checkRegion = checkRegion. substring ( from: checkRegion. index ( checkRegion. startIndex, offsetBy: NSMaxRange ( range ) ) )
473
474
}
474
475
475
476
if j == e {
@@ -614,24 +615,23 @@ private class Pattern {
614
615
/// Matches the pattern string against the input buffer.
615
616
///
616
617
/// This returns the position that is matched or npos if there is no match. If
617
- /// there is a match, the size of the matched string is returned in \p
618
- /// MatchLen.
618
+ /// there is a match, the range of the match is returned.
619
619
///
620
- /// The \p VariableTable StringMap provides the current values of filecheck
621
- /// variables and is updated if this match defines new values.
622
- func match( _ buffer : String , _ variableTable : BoxedTable ) -> ( Int , Int ) ? {
620
+ /// The variable table provides the current values of filecheck variables and
621
+ /// is updated if this match defines new values.
622
+ func match( _ buffer : String , _ variableTable : BoxedTable ) -> NSRange ? {
623
623
var matchLen : Int = 0
624
624
// If this is the EOF pattern, match it immediately.
625
625
if self . type == . EOF {
626
626
matchLen = 0
627
- return ( buffer. utf8. count, matchLen)
627
+ return NSRange ( location : buffer. utf8. count, length : matchLen)
628
628
}
629
629
630
630
// If this is a fixed string pattern, just match it now.
631
631
if !self . fixedString. isEmpty {
632
632
matchLen = self . fixedString. utf8. count
633
633
if let b = buffer. range ( of: self . fixedString) ? . lowerBound {
634
- return ( buffer. distance ( from: buffer. startIndex, to: b) , matchLen)
634
+ return NSRange ( location : buffer. distance ( from: buffer. startIndex, to: b) , length : matchLen)
635
635
}
636
636
return nil
637
637
}
@@ -696,14 +696,14 @@ private class Pattern {
696
696
}
697
697
698
698
matchLen = fullMatch. range. length
699
- return ( fullMatch. range. location, matchLen)
699
+ return NSRange ( location : fullMatch. range. location, length : matchLen)
700
700
}
701
701
702
702
/// Finds the closing sequence of a regex variable usage or definition.
703
703
///
704
- /// \p Str has to point in the beginning of the definition (right after the
705
- /// opening sequence). Returns the offset of the closing sequence within Str,
706
- /// or npos if it was not found.
704
+ /// The given string has to start in the beginning of the definition
705
+ /// (right after the opening sequence). Returns the offset of the closing
706
+ /// sequence within the string, or nil if it was not found.
707
707
private func findRegexVarEnd( _ regVar : String , brackets: ( open: Character , close: Character ) , terminator: String ) -> String . Index ? {
708
708
var string = regVar
709
709
// Offset keeps track of the current offset within the input Str
@@ -752,11 +752,6 @@ private class Pattern {
752
752
}
753
753
754
754
/// Parses the given string into the Pattern.
755
- ///
756
- /// \p Prefix provides which prefix is being matched, \p SM provides the
757
- /// SourceMgr used for error reports, and \p LineNumber is the line number in
758
- /// the input file from which the pattern string was read. Returns true in
759
- /// case of an error, false otherwise.
760
755
func parse( in buf : UnsafeBufferPointer < CChar > , pattern : UnsafeBufferPointer < CChar > , withPrefix prefix : String , at lineNumber : Int , options: FileCheckOptions ) -> Bool {
761
756
func mino( _ l : String . Index ? , _ r : String . Index ? ) -> String . Index ? {
762
757
if l == nil && r == nil {
@@ -975,22 +970,21 @@ func countNumNewlinesBetween(_ r : String) -> (Int, String.Index?) {
975
970
976
971
/// CheckString - This is a check that we found in the input file.
977
972
private struct CheckString {
978
- /// Pat - The pattern to match.
973
+ /// The pattern to match.
979
974
let pattern : Pattern
980
975
981
- /// Prefix - Which prefix name this check matched.
976
+ /// Which prefix name this check matched.
982
977
let prefix : String
983
978
984
- /// Loc - The location in the match file that the check string was specified.
979
+ /// The location in the match file that the check string was specified.
985
980
let loc : CheckLoc
986
981
987
- /// DagNotStrings - These are all of the strings that are disallowed from
988
- /// occurring between this match string and the previous one (or start of
989
- /// file).
982
+ /// These are all of the strings that are disallowed from occurring between
983
+ /// this match string and the previous one (or start of file).
990
984
let dagNotStrings : Array < Pattern > = [ ]
991
985
992
986
/// Match check string and its "not strings" and/or "dag strings".
993
- func check( _ buffer : String , _ isLabelScanMode : Bool , _ variableTable : BoxedTable ) -> ( Int , Int ) ? {
987
+ func check( _ buffer : String , _ isLabelScanMode : Bool , _ variableTable : BoxedTable ) -> NSRange ? {
994
988
var lastPos = 0
995
989
996
990
// IsLabelScanMode is true when we are scanning forward to find CHECK-LABEL
@@ -1007,7 +1001,7 @@ private struct CheckString {
1007
1001
1008
1002
// Match itself from the last position after matching CHECK-DAG.
1009
1003
let matchBuffer = buffer. substring ( from: buffer. index ( buffer. startIndex, offsetBy: lastPos) )
1010
- guard let ( matchPos , matchLen ) = self . pattern. match ( matchBuffer, variableTable) else {
1004
+ guard let range = self . pattern. match ( matchBuffer, variableTable) else {
1011
1005
if self . pattern. fixedString. isEmpty {
1012
1006
diagnose ( . error, self . loc, self . prefix + " : could not find a match for regex ' \( self . pattern. regExPattern) ' in input " )
1013
1007
} else if self . pattern. regExPattern. isEmpty {
@@ -1017,6 +1011,7 @@ private struct CheckString {
1017
1011
}
1018
1012
return nil
1019
1013
}
1014
+ let ( matchPos, matchLen) = ( range. location, range. length)
1020
1015
1021
1016
// Similar to the above, in "label-scan mode" we can't yet handle CHECK-NEXT
1022
1017
// or CHECK-NOT
@@ -1050,7 +1045,7 @@ private struct CheckString {
1050
1045
}
1051
1046
}
1052
1047
1053
- return ( lastPos + matchPos, matchLen)
1048
+ return NSRange ( location : lastPos + matchPos, length : matchLen)
1054
1049
}
1055
1050
1056
1051
/// Verify there is no newline in the given buffer.
@@ -1134,11 +1129,11 @@ private struct CheckString {
1134
1129
for pat in notStrings {
1135
1130
assert ( pat. type == . not, " Expect CHECK-NOT! " )
1136
1131
1137
- guard let ( Pos , _ ) /*(Pos, MatchLen)*/ = pat. match ( buffer, variableTable) else {
1132
+ guard let range = pat. match ( buffer, variableTable) else {
1138
1133
continue
1139
1134
}
1140
1135
buffer. cString ( using: . utf8) ? . withUnsafeBufferPointer { buf in
1141
- let loc = CheckLoc . inBuffer ( buf. baseAddress!. advanced ( by: Pos ) , buf)
1136
+ let loc = CheckLoc . inBuffer ( buf. baseAddress!. advanced ( by: range . location ) , buf)
1142
1137
diagnose ( . error, loc, self . prefix + " -NOT: string occurred! " )
1143
1138
}
1144
1139
diagnose ( . note, pat. patternLoc, self . prefix + " -NOT: pattern specified here " )
@@ -1172,12 +1167,12 @@ private struct CheckString {
1172
1167
let matchBuffer = buffer. substring ( from: buffer. index ( buffer. startIndex, offsetBy: startPos) )
1173
1168
// With a group of CHECK-DAGs, a single mismatching means the match on
1174
1169
// that group of CHECK-DAGs fails immediately.
1175
- guard let t = pattern. match ( matchBuffer, variableTable) else {
1170
+ guard let range = pattern. match ( matchBuffer, variableTable) else {
1176
1171
// PrintCheckFailed(SM, Pat.getLoc(), Pat, MatchBuffer, VariableTable)
1177
1172
return nil
1178
1173
}
1179
- var matchPos = t . 0
1180
- let matchLen = t . 1
1174
+ var matchPos = range . location
1175
+ let matchLen = range . length
1181
1176
1182
1177
// Re-calc it as the offset relative to the start of the original string.
1183
1178
matchPos += startPos
0 commit comments