@@ -990,8 +990,14 @@ evaluateAttachedMacro(MacroDecl *macro, Decl *attachedTo, CustomAttr *attr,
990
990
Lexer::getCharSourceRangeFromSourceRange (sourceMgr, *initRange);
991
991
} else {
992
992
// The accessors go at the end.
993
+ SourceLoc endLoc = storage->getEndLoc ();
994
+ if (auto var = dyn_cast<VarDecl>(storage)) {
995
+ if (auto pattern = var->getParentPattern ())
996
+ endLoc = pattern->getEndLoc ();
997
+ }
998
+
993
999
generatedOriginalSourceRange = CharSourceRange (
994
- Lexer::getLocForEndOfToken (sourceMgr, storage-> getEndLoc () ), 0 );
1000
+ Lexer::getLocForEndOfToken (sourceMgr, endLoc ), 0 );
995
1001
}
996
1002
997
1003
break ;
@@ -1064,15 +1070,15 @@ evaluateAttachedMacro(MacroDecl *macro, Decl *attachedTo, CustomAttr *attr,
1064
1070
return macroSourceFile;
1065
1071
}
1066
1072
1067
- void swift::expandAccessors (
1073
+ Optional< unsigned > swift::expandAccessors (
1068
1074
AbstractStorageDecl *storage, CustomAttr *attr, MacroDecl *macro
1069
1075
) {
1070
1076
// Evaluate the macro.
1071
1077
auto macroSourceFile = evaluateAttachedMacro (macro, storage, attr,
1072
1078
/* passParentContext*/ false ,
1073
1079
MacroRole::Accessor);
1074
1080
if (!macroSourceFile)
1075
- return ;
1081
+ return None ;
1076
1082
1077
1083
PrettyStackTraceDecl debugStack (
1078
1084
" type checking expanded declaration macro" , storage);
@@ -1098,6 +1104,22 @@ void swift::expandAccessors(
1098
1104
}
1099
1105
}
1100
1106
}
1107
+
1108
+ return macroSourceFile->getBufferID ();
1109
+ }
1110
+
1111
+ ArrayRef<unsigned > ExpandAccessorMacros::evaluate (
1112
+ Evaluator &evaluator, AbstractStorageDecl *storage
1113
+ ) const {
1114
+ llvm::SmallVector<unsigned , 1 > bufferIDs;
1115
+ storage->forEachAttachedMacro (MacroRole::Accessor,
1116
+ [&](CustomAttr *customAttr, MacroDecl *macro) {
1117
+ if (auto bufferID = expandAccessors (
1118
+ storage, customAttr, macro))
1119
+ bufferIDs.push_back (*bufferID);
1120
+ });
1121
+
1122
+ return storage->getASTContext ().AllocateCopy (bufferIDs);
1101
1123
}
1102
1124
1103
1125
Optional<unsigned >
0 commit comments