Skip to content

Commit 5ba6c91

Browse files
author
Harlan Haskins
committed
---
yaml --- r: 341735 b: refs/heads/rxwei-patch-1 c: db7a726 h: refs/heads/master i: 341733: 649ad96 341731: ea22efc 341727: 01d02b2
1 parent b43b601 commit 5ba6c91

39 files changed

+254
-204
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: 1f67b41997377ed19dec1961f43f787c05e46934
1018+
refs/heads/rxwei-patch-1: db7a726a7fb9900cbd074d53fa4dd4bc097cf59a
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/include/swift/AST/Expr.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,12 @@ class CodeCompletionExpr : public Expr {
599599
class LiteralExpr : public Expr {
600600
public:
601601
LiteralExpr(ExprKind Kind, bool Implicit) : Expr(Kind, Implicit) {}
602+
603+
// Make an exact copy of this one AST node.
604+
LiteralExpr *
605+
shallowClone(ASTContext &Ctx,
606+
llvm::function_ref<void(Expr *, Type)> setType,
607+
llvm::function_ref<Type(const Expr *)> getType) const;
602608

603609
static bool classof(const Expr *E) {
604610
return E->getKind() >= ExprKind::First_LiteralExpr &&
@@ -1125,6 +1131,7 @@ class ObjectLiteralExpr final
11251131

11261132
private:
11271133
Expr *Arg;
1134+
Expr *SemanticExpr;
11281135
SourceLoc PoundLoc;
11291136
ConcreteDeclRef Initializer;
11301137

@@ -1174,6 +1181,9 @@ class ObjectLiteralExpr final
11741181
return Bits.ObjectLiteralExpr.HasTrailingClosure;
11751182
}
11761183

1184+
Expr *getSemanticExpr() const { return SemanticExpr; }
1185+
void setSemanticExpr(Expr *expr) { SemanticExpr = expr; }
1186+
11771187
SourceLoc getSourceLoc() const { return PoundLoc; }
11781188
SourceRange getSourceRange() const {
11791189
return SourceRange(PoundLoc, Arg->getEndLoc());

branches/rxwei-patch-1/include/swift/AST/SimpleRequest.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ namespace detail {
113113

114114
/// Extract the first, nearest source location from a tuple.
115115
template<unsigned Index, typename ...Types,
116-
typename = typename std::enable_if<sizeof...(Types) - Index
117-
? true
118-
: false>::type>
116+
typename = typename std::enable_if<Index < sizeof...(Types)>::type>
119117
SourceLoc extractNearestSourceLocTuple(const std::tuple<Types...> &value) {
120118
SourceLoc loc = maybeExtractNearestSourceLoc(std::get<Index>(value));
121119
if (loc.isValid())

branches/rxwei-patch-1/include/swift/Basic/SourceManager.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,9 @@ class SourceManager {
231231
void verifyAllBuffers() const;
232232

233233
/// Translate line and column pair to the offset.
234-
/// If the column number is the maximum unsinged int, return the offset of the end of the line.
235234
llvm::Optional<unsigned> resolveFromLineCol(unsigned BufferId, unsigned Line,
236235
unsigned Col) const;
237236

238-
/// Translate the end position of the given line to the offset.
239-
llvm::Optional<unsigned> resolveOffsetForEndOfLine(unsigned BufferId,
240-
unsigned Line) const;
241-
242237
SourceLoc getLocForLineCol(unsigned BufferId, unsigned Line, unsigned Col) const {
243238
auto Offset = resolveFromLineCol(BufferId, Line, Col);
244239
return Offset.hasValue() ? getLocForOffset(BufferId, Offset.getValue()) :

branches/rxwei-patch-1/lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,7 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
19771977
printArgumentLabels(E->getArgumentLabels());
19781978
OS << "\n";
19791979
printRec(E->getArg());
1980+
printSemanticExpr(E->getSemanticExpr());
19801981
PrintWithColorRAII(OS, ParenthesisColor) << ')';
19811982
}
19821983

branches/rxwei-patch-1/lib/AST/ASTWalker.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
484484
}
485485

486486
Expr *visitObjectLiteralExpr(ObjectLiteralExpr *E) {
487+
HANDLE_SEMANTIC_EXPR(E);
488+
487489
if (Expr *arg = E->getArg()) {
488490
if (Expr *arg2 = doIt(arg)) {
489491
E->setArg(arg2);

branches/rxwei-patch-1/lib/AST/Expr.cpp

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,104 @@ llvm::DenseMap<Expr *, unsigned> Expr::getPreorderIndexMap() {
773773
// Support methods for Exprs.
774774
//===----------------------------------------------------------------------===//
775775

776+
static LiteralExpr *
777+
shallowCloneImpl(const NilLiteralExpr *E, ASTContext &Ctx,
778+
llvm::function_ref<Type(const Expr *)> getType) {
779+
return new (Ctx) NilLiteralExpr(E->getLoc());
780+
}
781+
782+
static LiteralExpr *
783+
shallowCloneImpl(const IntegerLiteralExpr *E, ASTContext &Ctx,
784+
llvm::function_ref<Type(const Expr *)> getType) {
785+
auto res = new (Ctx) IntegerLiteralExpr(E->getDigitsText(),
786+
E->getSourceRange().End);
787+
if (E->isNegative())
788+
res->setNegative(E->getSourceRange().Start);
789+
return res;
790+
}
791+
792+
static LiteralExpr *
793+
shallowCloneImpl(const FloatLiteralExpr *E, ASTContext &Ctx,
794+
llvm::function_ref<Type(const Expr *)> getType) {
795+
auto res = new (Ctx) FloatLiteralExpr(E->getDigitsText(),
796+
E->getSourceRange().End);
797+
if (E->isNegative())
798+
res->setNegative(E->getSourceRange().Start);
799+
return res;
800+
}
801+
static LiteralExpr *
802+
shallowCloneImpl(const BooleanLiteralExpr *E, ASTContext &Ctx,
803+
llvm::function_ref<Type(const Expr *)> getType) {
804+
return new (Ctx) BooleanLiteralExpr(E->getValue(), E->getLoc());
805+
}
806+
static LiteralExpr *
807+
shallowCloneImpl(const StringLiteralExpr *E, ASTContext &Ctx,
808+
llvm::function_ref<Type(const Expr *)> getType) {
809+
auto res = new (Ctx) StringLiteralExpr(E->getValue(), E->getSourceRange());
810+
res->setEncoding(E->getEncoding());
811+
return res;
812+
}
813+
814+
static LiteralExpr *
815+
shallowCloneImpl(const InterpolatedStringLiteralExpr *E, ASTContext &Ctx,
816+
llvm::function_ref<Type(const Expr *)> getType) {
817+
auto res = new (Ctx) InterpolatedStringLiteralExpr(E->getLoc(),
818+
E->getTrailingQuoteLoc(),
819+
E->getLiteralCapacity(),
820+
E->getInterpolationCount(),
821+
E->getAppendingExpr());
822+
res->setSemanticExpr(E->getSemanticExpr());
823+
return res;
824+
}
825+
826+
static LiteralExpr *
827+
shallowCloneImpl(const MagicIdentifierLiteralExpr *E, ASTContext &Ctx,
828+
llvm::function_ref<Type(const Expr *)> getType) {
829+
auto res = new (Ctx) MagicIdentifierLiteralExpr(E->getKind(),
830+
E->getSourceRange().End);
831+
if (res->isString())
832+
res->setStringEncoding(E->getStringEncoding());
833+
return res;
834+
}
835+
836+
static LiteralExpr *
837+
shallowCloneImpl(const ObjectLiteralExpr *E, ASTContext &Ctx,
838+
llvm::function_ref<Type(const Expr *)> getType) {
839+
auto res =
840+
ObjectLiteralExpr::create(Ctx, E->getStartLoc(), E->getLiteralKind(),
841+
E->getArg(), E->isImplicit(), getType);
842+
res->setSemanticExpr(E->getSemanticExpr());
843+
return res;
844+
}
845+
846+
// Make an exact copy of this AST node.
847+
LiteralExpr *LiteralExpr::shallowClone(
848+
ASTContext &Ctx, llvm::function_ref<void(Expr *, Type)> setType,
849+
llvm::function_ref<Type(const Expr *)> getType) const {
850+
LiteralExpr *Result = nullptr;
851+
switch (getKind()) {
852+
default: llvm_unreachable("Unknown literal type!");
853+
#define DISPATCH_CLONE(KIND) \
854+
case ExprKind::KIND: \
855+
Result = shallowCloneImpl(cast<KIND##Expr>(this), Ctx, getType); \
856+
break;
857+
858+
DISPATCH_CLONE(NilLiteral)
859+
DISPATCH_CLONE(IntegerLiteral)
860+
DISPATCH_CLONE(FloatLiteral)
861+
DISPATCH_CLONE(BooleanLiteral)
862+
DISPATCH_CLONE(StringLiteral)
863+
DISPATCH_CLONE(InterpolatedStringLiteral)
864+
DISPATCH_CLONE(ObjectLiteral)
865+
DISPATCH_CLONE(MagicIdentifierLiteral)
866+
#undef DISPATCH_CLONE
867+
}
868+
869+
setType(Result, getType(this));
870+
Result->setImplicit(isImplicit());
871+
return Result;
872+
}
873+
776874
IntegerLiteralExpr * IntegerLiteralExpr::createFromUnsigned(ASTContext &C, unsigned value) {
777875
llvm::SmallString<8> Scratch;
778876
llvm::APInt(sizeof(unsigned)*8, value).toString(Scratch, 10, /*signed*/ false);
@@ -1098,7 +1196,7 @@ ObjectLiteralExpr::ObjectLiteralExpr(SourceLoc PoundLoc, LiteralKind LitKind,
10981196
bool hasTrailingClosure,
10991197
bool implicit)
11001198
: LiteralExpr(ExprKind::ObjectLiteral, implicit),
1101-
Arg(Arg), PoundLoc(PoundLoc) {
1199+
Arg(Arg), SemanticExpr(nullptr), PoundLoc(PoundLoc) {
11021200
Bits.ObjectLiteralExpr.LitKind = static_cast<unsigned>(LitKind);
11031201
assert(getLiteralKind() == LitKind);
11041202
Bits.ObjectLiteralExpr.NumArgLabels = argLabels.size();

branches/rxwei-patch-1/lib/Basic/SourceLoc.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -310,19 +310,12 @@ void CharSourceRange::dump(const SourceManager &SM) const {
310310
print(llvm::errs(), SM);
311311
}
312312

313-
llvm::Optional<unsigned>
314-
SourceManager::resolveOffsetForEndOfLine(unsigned BufferId,
315-
unsigned Line) const {
316-
return resolveFromLineCol(BufferId, Line, ~0u);
317-
}
318-
319313
llvm::Optional<unsigned> SourceManager::resolveFromLineCol(unsigned BufferId,
320314
unsigned Line,
321315
unsigned Col) const {
322316
if (Line == 0 || Col == 0) {
323317
return None;
324318
}
325-
const bool LineEnd = Col == ~0u;
326319
auto InputBuf = getLLVMSourceMgr().getMemoryBuffer(BufferId);
327320
const char *Ptr = InputBuf->getBufferStart();
328321
const char *End = InputBuf->getBufferEnd();
@@ -338,18 +331,14 @@ llvm::Optional<unsigned> SourceManager::resolveFromLineCol(unsigned BufferId,
338331
return None;
339332
}
340333
Ptr = LineStart;
334+
341335
// The <= here is to allow for non-inclusive range end positions at EOF
342-
for (; ; ++Ptr) {
336+
for (; Ptr <= End; ++Ptr) {
343337
--Col;
344338
if (Col == 0)
345339
return Ptr - InputBuf->getBufferStart();
346-
if (*Ptr == '\n' || Ptr == End) {
347-
if (LineEnd) {
348-
return Ptr - InputBuf->getBufferStart();
349-
} else {
350-
break;
351-
}
352-
}
340+
if (*Ptr == '\n')
341+
break;
353342
}
354343
return None;
355344
}

branches/rxwei-patch-1/lib/Frontend/ParseableInterfaceModuleLoader.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class swift::ParseableInterfaceBuilder {
504504
// Note that we don't assume cachePath is the same as the Clang
505505
// module cache path at this point.
506506
if (!moduleCachePath.empty())
507-
(void)llvm::sys::fs::create_directory(moduleCachePath);
507+
(void)llvm::sys::fs::create_directories(moduleCachePath);
508508

509509
configureSubInvocationInputsAndOutputs(OutPath);
510510

@@ -1267,6 +1267,10 @@ class ParseableInterfaceModuleLoaderImpl {
12671267
depsAdjustedToMTime.push_back(adjustedDep);
12681268
}
12691269

1270+
// Create the module cache if we haven't created it yet.
1271+
StringRef parentDir = path::parent_path(outputPath);
1272+
(void)llvm::sys::fs::create_directories(parentDir);
1273+
12701274
auto hadError = withOutputFile(diags, outputPath,
12711275
[&](llvm::raw_pwrite_stream &out) {
12721276
llvm::yaml::Output yamlWriter(out);

0 commit comments

Comments
 (0)