Skip to content

Commit f6dd5d1

Browse files
committed
Update for review
1 parent 4243599 commit f6dd5d1

File tree

8 files changed

+37
-36
lines changed

8 files changed

+37
-36
lines changed

include/swift/IDETool/SyntacticMacroExpansion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class SyntacticMacroExpansionInstance {
5656
const MacroExpansionSpecifier &expansion);
5757

5858
/// Expand single 'expansion' in SF.
59-
bool getExpansion(swift::SourceFile *SF,
59+
bool expand(swift::SourceFile *SF,
6060
const MacroExpansionSpecifier &expansion,
6161
SourceEditConsumer &consumer);
6262

@@ -71,7 +71,7 @@ class SyntacticMacroExpansionInstance {
7171

7272
/// Expand all macros in \p inputBuf and send the edit results to \p consumer.
7373
/// Expansions are specified by \p expansions .
74-
bool getExpansions(llvm::MemoryBuffer *inputBuf,
74+
bool expandAll(llvm::MemoryBuffer *inputBuf,
7575
ArrayRef<MacroExpansionSpecifier> expansions,
7676
SourceEditConsumer &consumer);
7777
};

lib/IDETool/SyntacticMacroExpansion.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ expandFreestandingMacro(MacroDecl *macro,
219219
std::vector<unsigned> bufferIDs;
220220

221221
SmallString<32> discriminator;
222-
discriminator.append("macro_");
222+
discriminator.append("__syntactic_macro_");
223223
addExpansionDiscriminator(discriminator,
224224
expansion->getDeclContext()->getParentSourceFile(),
225225
expansion->getPoundLoc());
@@ -406,7 +406,7 @@ class MacroExpansionFinder : public ASTWalker {
406406
};
407407
} // namespace
408408

409-
bool SyntacticMacroExpansionInstance::getExpansion(
409+
bool SyntacticMacroExpansionInstance::expand(
410410
SourceFile *SF, const MacroExpansionSpecifier &expansion,
411411
SourceEditConsumer &consumer) {
412412

@@ -458,7 +458,7 @@ bool SyntacticMacroExpansionInstance::getExpansion(
458458
return false;
459459
}
460460

461-
bool SyntacticMacroExpansionInstance::getExpansions(
461+
bool SyntacticMacroExpansionInstance::expandAll(
462462
llvm::MemoryBuffer *inputBuf, ArrayRef<MacroExpansionSpecifier> expansions,
463463
SourceEditConsumer &consumer) {
464464

@@ -467,7 +467,7 @@ bool SyntacticMacroExpansionInstance::getExpansions(
467467

468468
bool hasError = false;
469469
for (const auto &expansion : expansions) {
470-
hasError |= getExpansion(SF, expansion, consumer);
470+
hasError |= expand(SF, expansion, consumer);
471471
}
472472
return hasError;
473473
}

test/SourceKit/Macros/syntactic_expansion.swift.expected

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,53 +29,53 @@ source.edit.kind.active:
2929
10:3-10:3 "@Wrapper"
3030
source.edit.kind.active:
3131
12:3-12:35 "struct blah8 {
32-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu_() {
32+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu_() {
3333
}
34-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu0_() {
34+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu0_() {
3535
}
3636
}
3737
struct blah16 {
38-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu1_() {
38+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu1_() {
3939
}
40-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu2_() {
40+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu2_() {
4141
}
4242
}
4343
struct blah32 {
44-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu3_() {
44+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu3_() {
4545
}
46-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu4_() {
46+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu4_() {
4747
}
4848
}
4949
struct blah64 {
50-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu5_() {
50+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu5_() {
5151
}
52-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu6_() {
52+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu6_() {
5353
}
5454
}"
5555
### 2
5656
source.edit.kind.active:
5757
12:3-12:35 "struct blah8 {
58-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu_() {
58+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu_() {
5959
}
60-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu0_() {
60+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu0_() {
6161
}
6262
}
6363
struct blah16 {
64-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu1_() {
64+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu1_() {
6565
}
66-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu2_() {
66+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu2_() {
6767
}
6868
}
6969
struct blah32 {
70-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu3_() {
70+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu3_() {
7171
}
72-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu4_() {
72+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu4_() {
7373
}
7474
}
7575
struct blah64 {
76-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu5_() {
76+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu5_() {
7777
}
78-
func macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu6_() {
78+
func __syntactic_macro_a01f07de3e9ee8585adf794ccd6dec8c6methodfMu6_() {
7979
}
8080
}"
8181
source.edit.kind.active:

tools/SourceKit/include/SourceKit/Core/LangSupport.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ struct MacroExpansionInfo {
244244
};
245245
// See swift::ExpandedMacroDefinition.
246246
struct ExpandedMacroDefinition {
247+
// 'Replacement.range' references some part of code in 'expansionText'.
248+
// 'expansionText' will be replaced by the 'parameterIndex'-th argument of
249+
// the macro.
247250
struct Replacement {
248251
RawCharSourceRange range;
249252
unsigned parameterIndex;
@@ -257,7 +260,8 @@ struct MacroExpansionInfo {
257260
: expansionText(expansionText), replacements(){};
258261
};
259262

260-
// Offset of the macro expansion syntax (i.e. attribute or #<macro name>)
263+
// Offset of the macro expansion syntax (i.e. attribute or #<macro name>) from
264+
// the start of the source file.
261265
unsigned offset;
262266

263267
// Macro roles.

tools/SourceKit/lib/SwiftLang/SwiftSyntacticMacroExpansion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ void SwiftLangSupport::expandMacroSyntactically(
8989
}
9090

9191
RequestRefactoringEditConsumer consumer(receiver);
92-
(void)instance->getExpansions(inputBuf, expansions, consumer);
92+
(void)instance->expandAll(inputBuf, expansions, consumer);
9393
// consumer automatically send the results on destruction.
9494
}

tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,10 @@ static bool readPopularAPIList(StringRef filename,
422422
/// where {path} is a path to a JSON file that has macro roles and definition.
423423
/// {line} and {column} is resolved to 'offset' using \p inputBuf .
424424
static bool setSyntacticMacroExpansions(sourcekitd_object_t req,
425-
TestOptions &Opts,
425+
TestOptions &opts,
426426
llvm::MemoryBuffer *inputBuf) {
427427
SmallVector<sourcekitd_object_t, 4> expansions;
428-
for (std::string &opt : Opts.RequestOptions) {
428+
for (std::string &opt : opts.RequestOptions) {
429429
SmallVector<StringRef, 3> args;
430430
StringRef(opt).split(args, ":");
431431
unsigned line, column;
@@ -437,7 +437,7 @@ static bool setSyntacticMacroExpansions(sourcekitd_object_t req,
437437
}
438438
unsigned offset = resolveFromLineCol(line, column, inputBuf);
439439

440-
auto Buffer = getBufferForFilename(args[2], Opts.VFSFiles)->getBuffer();
440+
auto Buffer = getBufferForFilename(args[2], opts.VFSFiles)->getBuffer();
441441
char *Err = nullptr;
442442
auto expansion = sourcekitd_request_create_from_yaml(Buffer.data(), &Err);
443443
if (!expansion) {
@@ -1150,7 +1150,7 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) {
11501150

11511151
case SourceKitRequest::SyntacticMacroExpansion:
11521152
sourcekitd_request_dictionary_set_uid(Req, KeyRequest,
1153-
RequestExpandMacroSyntactically);
1153+
RequestSyntacticMacroExpansion);
11541154
setSyntacticMacroExpansions(Req, Opts, SourceBuf.get());
11551155
break;
11561156
}

tools/SourceKit/tools/sourcekitd/lib/Service/Requests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,7 @@ handleRequestDiagnostics(const RequestDict &Req,
18451845
/// Sends the results as a 'CategorizedEdits'.
18461846
/// Note that, unlike refactoring, each edit doesn't have 'key.buffer_name'.
18471847
/// FIXME: Support nested expansion.
1848-
static void handleRequestExpandMacroSyntactically(
1848+
static void handleRequestSyntacticMacroExpansion(
18491849
const RequestDict &req, SourceKitCancellationToken cancellationToken,
18501850
ResponseReceiver rec) {
18511851

@@ -2055,8 +2055,8 @@ void handleRequestImpl(sourcekitd_object_t ReqObj,
20552055
HANDLE_REQUEST(RequestRelatedIdents, handleRequestRelatedIdents)
20562056
HANDLE_REQUEST(RequestActiveRegions, handleRequestActiveRegions)
20572057
HANDLE_REQUEST(RequestDiagnostics, handleRequestDiagnostics)
2058-
HANDLE_REQUEST(RequestExpandMacroSyntactically,
2059-
handleRequestExpandMacroSyntactically)
2058+
HANDLE_REQUEST(RequestSyntacticMacroExpansion,
2059+
handleRequestSyntacticMacroExpansion)
20602060

20612061
{
20622062
SmallString<64> ErrBuf;

utils/gyb_sourcekit_support/UIDs.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,9 @@ def __init__(self, internal_name, external_name):
276276
REQUEST('Diagnostics', 'source.request.diagnostics'),
277277
REQUEST('Compile', 'source.request.compile'),
278278
REQUEST('CompileClose', 'source.request.compile.close'),
279-
<<<<<<< HEAD
280279
REQUEST('EnableRequestBarriers', 'source.request.enable_request_barriers'),
281-
=======
282-
REQUEST('ExpandMacroSyntactically',
283-
'source.request.expand.macro.syntactically'),
284-
>>>>>>> 309c87b56fa ([SourceKit] Add request to expand macros syntactically)
280+
REQUEST('SyntacticMacroExpansion',
281+
'source.request.syntactic_macro_expansion'),
285282
]
286283

287284

0 commit comments

Comments
 (0)