22
22
#include " swift/Basic/SourceManager.h"
23
23
#include " swift/Parse/Lexer.h"
24
24
#include " swift/Parse/Token.h"
25
+ #include " swift/Config.h"
25
26
#include " swift/Subsystems.h"
26
27
#include " llvm/ADT/StringSwitch.h"
27
28
#include " llvm/Support/MemoryBuffer.h"
@@ -238,8 +239,8 @@ class ModelASTWalker : public ASTWalker {
238
239
unsigned BufferID;
239
240
std::vector<StructureElement> SubStructureStack;
240
241
SourceLoc LastLoc;
241
- static const std::regex URLRxs[ 3 ] ;
242
- static const std::regex DocCommentRxs[ 3 ] ;
242
+ static const std::regex & getURLRegex ( unsigned Index) ;
243
+ static const std::regex & getDocCommentRegex ( unsigned Index) ;
243
244
244
245
Optional<SyntaxNode> parseFieldNode (StringRef Text, StringRef OrigText,
245
246
SourceLoc OrigLoc);
@@ -307,26 +308,32 @@ class ModelASTWalker : public ASTWalker {
307
308
}
308
309
};
309
310
310
- const std::regex ModelASTWalker::URLRxs[3 ] = {
311
+ const std::regex &ModelASTWalker::getURLRegex (unsigned Index) {
312
+ static const std::regex Regexes[3 ] = {
311
313
std::regex{ RegexStrURL, std::regex::ECMAScript | std::regex::nosubs },
312
314
std::regex{ RegexStrMailURL, std::regex::ECMAScript | std::regex::nosubs },
313
315
std::regex{ RegexStrRadarURL, std::regex::ECMAScript | std::regex::nosubs }
314
- };
316
+ };
317
+ return Regexes[Index];
318
+ }
315
319
316
- const std::regex ModelASTWalker::DocCommentRxs[3 ] = {
317
- std::regex {
318
- RegexStrParameter,
319
- std::regex::egrep | std::regex::icase | std::regex::optimize
320
- },
321
- std::regex {
322
- RegexStrDocCommentParametersHeading,
323
- std::regex::egrep | std::regex::icase | std::regex::optimize
324
- },
325
- std::regex {
326
- RegexStrDocCommentField,
327
- std::regex::egrep | std::regex::icase | std::regex::optimize
328
- }
329
- };
320
+ const std::regex &ModelASTWalker::getDocCommentRegex (unsigned Index) {
321
+ static const std::regex Regexes[3 ] = {
322
+ std::regex {
323
+ RegexStrParameter,
324
+ std::regex::egrep | std::regex::icase | std::regex::optimize
325
+ },
326
+ std::regex {
327
+ RegexStrDocCommentParametersHeading,
328
+ std::regex::egrep | std::regex::icase | std::regex::optimize
329
+ },
330
+ std::regex {
331
+ RegexStrDocCommentField,
332
+ std::regex::egrep | std::regex::icase | std::regex::optimize
333
+ }
334
+ };
335
+ return Regexes[Index];
336
+ }
330
337
331
338
SyntaxStructureKind syntaxStructureKindFromNominalTypeDecl (NominalTypeDecl *N) {
332
339
if (isa<ClassDecl>(N))
@@ -1291,6 +1298,10 @@ bool ModelASTWalker::processComment(CharSourceRange Range) {
1291
1298
bool ModelASTWalker::findUrlStartingLoc (StringRef Text,
1292
1299
unsigned &Start,
1293
1300
std::regex &Regex) {
1301
+ #ifndef SWIFT_HAVE_WORKING_STD_REGEX
1302
+ return false ;
1303
+ #endif
1304
+
1294
1305
static const auto MailToPosition = std::find (URLProtocols.begin (),
1295
1306
URLProtocols.end (),
1296
1307
" mailto" );
@@ -1306,11 +1317,11 @@ bool ModelASTWalker::findUrlStartingLoc(StringRef Text,
1306
1317
Text.substr (Index - It->size (), It->size ()) == *It) {
1307
1318
Start = Index - It->size ();
1308
1319
if (It < MailToPosition)
1309
- Regex = URLRxs[ 0 ] ;
1320
+ Regex = getURLRegex ( 0 ) ;
1310
1321
else if (It < RadarPosition)
1311
- Regex = URLRxs[ 1 ] ;
1322
+ Regex = getURLRegex ( 1 ) ;
1312
1323
else
1313
- Regex = URLRxs[ 2 ] ;
1324
+ Regex = getURLRegex ( 2 ) ;
1314
1325
return true ;
1315
1326
}
1316
1327
}
@@ -1350,8 +1361,13 @@ bool ModelASTWalker::searchForURL(CharSourceRange Range) {
1350
1361
Optional<SyntaxNode> ModelASTWalker::parseFieldNode (StringRef Text,
1351
1362
StringRef OrigText,
1352
1363
SourceLoc OrigLoc) {
1364
+ #ifndef SWIFT_HAVE_WORKING_STD_REGEX
1365
+ return None;
1366
+ #endif
1367
+
1353
1368
std::match_results<StringRef::iterator> Matches;
1354
- for (auto &Rx : DocCommentRxs) {
1369
+ for (unsigned i = 0 ; i != 3 ; ++i) {
1370
+ auto &Rx = getDocCommentRegex (i);
1355
1371
bool HadMatch = std::regex_search (Text.begin (), Text.end (), Matches, Rx);
1356
1372
if (HadMatch)
1357
1373
break ;
0 commit comments