@@ -1987,17 +1987,64 @@ OpenedArchetypeType *OpenExistentialExpr::getOpenedArchetype() const {
19871987 return type->castTo <OpenedArchetypeType>();
19881988}
19891989
1990- KeyPathExpr::KeyPathExpr (ASTContext &C, SourceLoc keywordLoc,
1991- SourceLoc lParenLoc, ArrayRef<Component> components,
1992- SourceLoc rParenLoc, bool isImplicit)
1993- : Expr(ExprKind::KeyPath, isImplicit), StartLoc(keywordLoc),
1994- LParenLoc(lParenLoc), EndLoc(rParenLoc),
1995- Components(C.AllocateUninitialized<Component>(components.size())) {
1996- // Copy components into the AST context.
1997- std::uninitialized_copy (components.begin (), components.end (),
1998- Components.begin ());
1999-
2000- Bits.KeyPathExpr .IsObjC = true ;
1990+ KeyPathExpr::KeyPathExpr (SourceLoc startLoc, Expr *parsedRoot,
1991+ Expr *parsedPath, SourceLoc endLoc, bool hasLeadingDot,
1992+ bool isObjC, bool isImplicit)
1993+ : Expr(ExprKind::KeyPath, isImplicit), StartLoc(startLoc), EndLoc(endLoc),
1994+ ParsedRoot(parsedRoot), ParsedPath(parsedPath),
1995+ HasLeadingDot(hasLeadingDot) {
1996+ assert (!(isObjC && (parsedRoot || parsedPath)) &&
1997+ " Obj-C key paths should only have components" );
1998+ Bits.KeyPathExpr .IsObjC = isObjC;
1999+ }
2000+
2001+ KeyPathExpr::KeyPathExpr (SourceLoc backslashLoc, Expr *parsedRoot,
2002+ Expr *parsedPath, bool hasLeadingDot, bool isImplicit)
2003+ : KeyPathExpr(backslashLoc, parsedRoot, parsedPath,
2004+ parsedPath ? parsedPath->getEndLoc ()
2005+ : parsedRoot->getEndLoc(),
2006+ hasLeadingDot, /* isObjC*/ false, isImplicit) {
2007+ assert ((parsedRoot || parsedPath) &&
2008+ " Key path must have either root or path" );
2009+ }
2010+
2011+ KeyPathExpr::KeyPathExpr (ASTContext &ctx, SourceLoc startLoc,
2012+ ArrayRef<Component> components, SourceLoc endLoc,
2013+ bool isObjC, bool isImplicit)
2014+ : KeyPathExpr(startLoc, /* parsedRoot*/ nullptr , /* parsedPath*/ nullptr ,
2015+ endLoc, /* hasLeadingDot*/ false , isObjC, isImplicit) {
2016+ assert (!components.empty ());
2017+ Components = ctx.AllocateCopy (components);
2018+ }
2019+
2020+ KeyPathExpr *KeyPathExpr::createParsedPoundKeyPath (
2021+ ASTContext &ctx, SourceLoc keywordLoc, SourceLoc lParenLoc,
2022+ ArrayRef<Component> components, SourceLoc rParenLoc) {
2023+ return new (ctx) KeyPathExpr (ctx, keywordLoc, components, rParenLoc,
2024+ /* isObjC*/ true , /* isImplicit*/ false );
2025+ }
2026+
2027+ KeyPathExpr *KeyPathExpr::createParsed (ASTContext &ctx, SourceLoc backslashLoc,
2028+ Expr *parsedRoot, Expr *parsedPath,
2029+ bool hasLeadingDot) {
2030+ return new (ctx) KeyPathExpr (backslashLoc, parsedRoot, parsedPath,
2031+ hasLeadingDot, /* isImplicit*/ false );
2032+ }
2033+
2034+ KeyPathExpr *KeyPathExpr::createImplicit (ASTContext &ctx,
2035+ SourceLoc backslashLoc,
2036+ ArrayRef<Component> components,
2037+ SourceLoc endLoc) {
2038+ return new (ctx) KeyPathExpr (ctx, backslashLoc, components, endLoc,
2039+ /* isObjC*/ false , /* isImplicit*/ true );
2040+ }
2041+
2042+ KeyPathExpr *KeyPathExpr::createImplicit (ASTContext &ctx,
2043+ SourceLoc backslashLoc,
2044+ Expr *parsedRoot, Expr *parsedPath,
2045+ bool hasLeadingDot) {
2046+ return new (ctx) KeyPathExpr (backslashLoc, parsedRoot, parsedPath,
2047+ hasLeadingDot, /* isImplicit*/ true );
20012048}
20022049
20032050void
0 commit comments