Skip to content

Commit 2f3a77a

Browse files
committed
Address Ben's comments on r30290
Swift SVN r30325
1 parent 4e1efd5 commit 2f3a77a

File tree

1 file changed

+48
-38
lines changed

1 file changed

+48
-38
lines changed

lib/IDE/SyntaxModel.cpp

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ struct StructureElement {
188188
:StructureNode(StructureNode), ASTNode(ASTNode) { }
189189
};
190190

191-
static const std::vector<std::string> URLPro = {
191+
static const std::vector<std::string> URLProtocols = {
192192

193193
// Use RegexStrURL:
194194
"acap", "afp", "afs", "cid", "data", "fax", "feed", "file", "ftp", "go",
@@ -234,26 +234,11 @@ class ModelASTWalker : public ASTWalker {
234234
unsigned BufferID;
235235
std::vector<StructureElement> SubStructureStack;
236236
SourceLoc LastLoc;
237-
std::regex URLRxs[3] = {
238-
std::regex{ RegexStrURL, std::regex::ECMAScript | std::regex::nosubs },
239-
std::regex{ RegexStrMailURL, std::regex::ECMAScript | std::regex::nosubs },
240-
std::regex{ RegexStrRadarURL, std::regex::ECMAScript | std::regex::nosubs }};
241-
242-
std::regex DocCommentRxs[3] = {
243-
std::regex {
244-
RegexStrParameter,
245-
std::regex::egrep | std::regex::icase | std::regex::optimize
246-
},
247-
std::regex {
248-
RegexStrDocCommentParametersHeading,
249-
std::regex::egrep | std::regex::icase | std::regex::optimize
250-
},
251-
std::regex { RegexStrDocCommentField,
252-
std::regex::egrep | std::regex::icase | std::regex::optimize
253-
}
254-
};
237+
static const std::regex URLRxs[3];
238+
static const std::regex DocCommentRxs[3];
255239

256-
Optional<SyntaxNode> parseFieldNode(StringRef Text, StringRef OrigText, SourceLoc OrigLoc);
240+
Optional<SyntaxNode> parseFieldNode(StringRef Text, StringRef OrigText,
241+
SourceLoc OrigLoc);
257242

258243
public:
259244
SyntaxModelWalker &Walker;
@@ -276,7 +261,8 @@ class ModelASTWalker : public ASTWalker {
276261
bool shouldWalkIntoFunctionGenericParams() override { return true; }
277262

278263
private:
279-
bool findUrlStartingLoc(StringRef Text, unsigned &Start, std::regex& Regex);
264+
static bool findUrlStartingLoc(StringRef Text, unsigned &Start,
265+
std::regex& Regex);
280266
bool annotateIfConfigConditionIdentifiers(Expr *Cond);
281267
bool handleAttrs(const DeclAttributes &Attrs);
282268
bool handleAttrs(const TypeAttributes &Attrs);
@@ -308,6 +294,27 @@ class ModelASTWalker : public ASTWalker {
308294
bool findFieldsInDocCommentBlock(SyntaxNode Node);
309295
};
310296

297+
const std::regex ModelASTWalker::URLRxs[3] = {
298+
std::regex{ RegexStrURL, std::regex::ECMAScript | std::regex::nosubs },
299+
std::regex{ RegexStrMailURL, std::regex::ECMAScript | std::regex::nosubs },
300+
std::regex{ RegexStrRadarURL, std::regex::ECMAScript | std::regex::nosubs }
301+
};
302+
303+
const std::regex ModelASTWalker::DocCommentRxs[3] = {
304+
std::regex {
305+
RegexStrParameter,
306+
std::regex::egrep | std::regex::icase | std::regex::optimize
307+
},
308+
std::regex {
309+
RegexStrDocCommentParametersHeading,
310+
std::regex::egrep | std::regex::icase | std::regex::optimize
311+
},
312+
std::regex {
313+
RegexStrDocCommentField,
314+
std::regex::egrep | std::regex::icase | std::regex::optimize
315+
}
316+
};
317+
311318
SyntaxStructureKind syntaxStructureKindFromNominalTypeDecl(NominalTypeDecl *N) {
312319
if (isa<ClassDecl>(N))
313320
return SyntaxStructureKind::Class;
@@ -1179,24 +1186,27 @@ bool ModelASTWalker::processComment(CharSourceRange Range) {
11791186
bool ModelASTWalker::findUrlStartingLoc(StringRef Text,
11801187
unsigned &Start,
11811188
std::regex &Regex) {
1182-
static const auto MailToPosition = std::find(URLPro.begin(), URLPro.end(),
1189+
static const auto MailToPosition = std::find(URLProtocols.begin(),
1190+
URLProtocols.end(),
11831191
"mailto");
1184-
static const auto RadarPosition = std::find(URLPro.begin(), URLPro.end(),
1192+
static const auto RadarPosition = std::find(URLProtocols.begin(),
1193+
URLProtocols.end(),
11851194
"radar");
1186-
auto Index = Text.find("://");
1187-
if (Index != StringRef::npos) {
1188-
for (auto It = URLPro.begin(); It != URLPro.end(); ++ It) {
1189-
if (Index >= It->size() &&
1190-
Text.substr(Index - It->size(), It->size()) == *It) {
1191-
Start = Index - It->size();
1192-
if (It < MailToPosition)
1193-
Regex = URLRxs[0];
1194-
else if (It < RadarPosition)
1195-
Regex = URLRxs[1];
1196-
else
1197-
Regex = URLRxs[2];
1198-
return true;
1199-
}
1195+
auto Index = Text.find(":");
1196+
if (Index == StringRef::npos)
1197+
return false;
1198+
1199+
for (auto It = URLProtocols.begin(); It != URLProtocols.end(); ++ It) {
1200+
if (Index >= It->size() &&
1201+
Text.substr(Index - It->size(), It->size()) == *It) {
1202+
Start = Index - It->size();
1203+
if (It < MailToPosition)
1204+
Regex = URLRxs[0];
1205+
else if (It < RadarPosition)
1206+
Regex = URLRxs[1];
1207+
else
1208+
Regex = URLRxs[2];
1209+
return true;
12001210
}
12011211
}
12021212
return false;
@@ -1209,7 +1219,7 @@ bool ModelASTWalker::searchForURL(CharSourceRange Range) {
12091219
StringRef Text = OrigText;
12101220
while (1) {
12111221
std::match_results<StringRef::iterator> Matches;
1212-
std::regex &Regex = URLRxs[0];
1222+
std::regex Regex;
12131223
unsigned Start;
12141224
if (findUrlStartingLoc(Text, Start, Regex) &&
12151225
std::regex_search(Text.substr(Start).begin(),

0 commit comments

Comments
 (0)