@@ -250,6 +250,10 @@ Expr *ASTGen::generate(const ExprSyntax &E, const SourceLoc Loc) {
250
250
result = generate (*dictionaryExpr, Loc);
251
251
else if (auto tupleExpr = E.getAs <TupleExprSyntax>())
252
252
result = generate (*tupleExpr, Loc);
253
+ else if (auto callExpr = E.getAs <FunctionCallExprSyntax>())
254
+ result = generate (*callExpr, Loc);
255
+ else if (auto memberExpr = E.getAs <MemberAccessExprSyntax>())
256
+ result = generate (*memberExpr, Loc);
253
257
else if (auto integerLiteralExpr = E.getAs <IntegerLiteralExprSyntax>())
254
258
result = generate (*integerLiteralExpr, Loc);
255
259
else if (auto floatLiteralExpr = E.getAs <FloatLiteralExprSyntax>())
@@ -268,6 +272,10 @@ Expr *ASTGen::generate(const ExprSyntax &E, const SourceLoc Loc) {
268
272
result = generate (*poundFunctionExpr, Loc);
269
273
else if (auto poundDsohandleExpr = E.getAs <PoundDsohandleExprSyntax>())
270
274
result = generate (*poundDsohandleExpr, Loc);
275
+ else if (auto objectLiteralExpr = E.getAs <ObjectLiteralExprSyntax>())
276
+ result = generate (*objectLiteralExpr, Loc);
277
+ else if (auto completionExpr = E.getAs <CodeCompletionExprSyntax>())
278
+ result = generate (*completionExpr, Loc);
271
279
else if (auto unknownExpr = E.getAs <UnknownExprSyntax>())
272
280
result = generate (*unknownExpr, Loc);
273
281
else {
@@ -593,6 +601,67 @@ void ASTGen::generateExprTupleElementList(const TupleExprElementListSyntax &elem
593
601
exprLabels.size () == exprLabelLocs.size ());
594
602
}
595
603
604
+ Expr *ASTGen::generate (const FunctionCallExprSyntax &E, const SourceLoc Loc) {
605
+ auto callee = E.getCalledExpression ();
606
+
607
+ SourceLoc LParenLoc, RParenLoc;
608
+ SmallVector<Expr *, 2 > args;
609
+ SmallVector<Identifier, 2 > argLabels;
610
+ SmallVector<SourceLoc, 2 > argLabelLocs;
611
+ generateExprTupleElementList (E.getArgumentList (), Loc,
612
+ /* isForCallArguments=*/ true , args, argLabels,
613
+ argLabelLocs);
614
+ Expr *trailingClosure = nullptr ;
615
+ if (auto CE = E.getTrailingClosure ())
616
+ trailingClosure = generate (*CE, Loc);
617
+ if (auto LParen = E.getLeftParen ()) {
618
+ LParenLoc = advanceLocBegin (Loc, *LParen);
619
+ if (auto RParen = E.getRightParen ())
620
+ RParenLoc = advanceLocBegin (Loc, *RParen);
621
+ else
622
+ RParenLoc = advanceLocEnd (Loc, E.getArgumentList ());
623
+ }
624
+
625
+ if (auto memberAccess = callee.getAs <MemberAccessExprSyntax>()) {
626
+ if (!memberAccess->getBase ()) {
627
+ // This is UnresolvedMemberExpr with call arguments.
628
+ if (memberAccess->getName ().isMissing ())
629
+ return nullptr ;
630
+
631
+ SourceLoc dotLoc = advanceLocBegin (Loc, memberAccess->getDot ());
632
+ DeclName name;
633
+ DeclNameLoc nameLoc;
634
+ std::tie (name, nameLoc) = generateUnqualifiedDeclName (
635
+ memberAccess->getName (), memberAccess->getDeclNameArguments (), Loc);
636
+
637
+ return UnresolvedMemberExpr::create (
638
+ Context, dotLoc, nameLoc, name, LParenLoc, args, argLabels,
639
+ argLabelLocs, RParenLoc, trailingClosure,
640
+ /* implicit=*/ false );
641
+ }
642
+ }
643
+ llvm_unreachable (" call expression not implemented" );
644
+ return nullptr ;
645
+ }
646
+
647
+ Expr *ASTGen::generate (const MemberAccessExprSyntax &E, const SourceLoc Loc) {
648
+ if (!E.getBase ()) {
649
+ // This is an UnresolvedMemberExpr.
650
+ if (E.getName ().isMissing ())
651
+ return nullptr ;
652
+
653
+ DeclName name;
654
+ DeclNameLoc nameLoc;
655
+ std::tie (name, nameLoc) =
656
+ generateUnqualifiedDeclName (E.getName (), E.getDeclNameArguments (), Loc);
657
+ SourceLoc dotLoc = advanceLocBegin (Loc, E.getDot ());
658
+
659
+ return UnresolvedMemberExpr::create (Context, dotLoc, nameLoc, name,
660
+ /* implicit=*/ false );
661
+ }
662
+ llvm_unreachable (" member access expression not implemented" );
663
+ return nullptr ;
664
+ }
596
665
597
666
Expr *ASTGen::generate (const IntegerLiteralExprSyntax &Expr,
598
667
const SourceLoc Loc) {
@@ -647,6 +716,64 @@ Expr *ASTGen::generate(const PoundDsohandleExprSyntax &Expr,
647
716
Loc);
648
717
}
649
718
719
+ Expr *ASTGen::generate (const ObjectLiteralExprSyntax &E, const SourceLoc Loc) {
720
+ ObjectLiteralExpr::LiteralKind kind;
721
+ switch (E.getIdentifier ().getTokenKind ()) {
722
+ #define POUND_OBJECT_LITERAL (Name, Desc, Proto ) \
723
+ case tok::pound_##Name: \
724
+ kind = ObjectLiteralExpr::Name; \
725
+ break ;
726
+ #include " swift/Syntax/TokenKinds.def"
727
+ default :
728
+ llvm_unreachable (" unknown token kind for object literal expression" );
729
+ }
730
+
731
+ SmallVector<Expr *, 2 > args;
732
+ SmallVector<Identifier, 2 > argLabels;
733
+ SmallVector<SourceLoc, 2 > argLabelLocs;
734
+ generateExprTupleElementList (E.getArguments (), Loc, true , args, argLabels,
735
+ argLabelLocs);
736
+
737
+ ClosureExpr *trailingClosure = nullptr ;
738
+ if (auto CE = E.getTrailingClosure ())
739
+ trailingClosure = dyn_cast_or_null<ClosureExpr>(generate (*CE, Loc));
740
+
741
+ if (E.getLeftParen ().isMissing () || E.getRightParen ().isMissing ())
742
+ return nullptr ;
743
+
744
+ SourceLoc poundLoc = advanceLocBegin (Loc, E.getIdentifier ());
745
+ SourceLoc LParenLoc = advanceLocBegin (Loc, E.getLeftParen ());
746
+ SourceLoc RParenLoc = advanceLocBegin (Loc, E.getRightParen ());
747
+
748
+ return ObjectLiteralExpr::create (Context, poundLoc, kind, LParenLoc, args,
749
+ argLabels, argLabelLocs, RParenLoc,
750
+ trailingClosure, /* implicit=*/ false );
751
+ }
752
+
753
+ Expr *ASTGen::generate (const CodeCompletionExprSyntax &E, const SourceLoc Loc) {
754
+ if (!E.getBase ()) {
755
+ if (auto punctuator = E.getPeriodOrParen ()) {
756
+ // '.' <cc-token>
757
+ if (punctuator->getTokenKind () == tok::period ||
758
+ punctuator->getTokenKind () == tok::period_prefix) {
759
+ auto ccLoc = advanceLocBegin (Loc, E.getCodeCompletionToken ());
760
+ auto dotLoc = advanceLocBegin (Loc, *punctuator);
761
+
762
+ auto CCE = new (Context) CodeCompletionExpr (ccLoc);
763
+ if (P.CodeCompletion )
764
+ P.CodeCompletion ->completeUnresolvedMember (CCE, dotLoc);
765
+ return CCE;
766
+ }
767
+ } else {
768
+ llvm_unreachable (" '(' <cc-token> is not suppported" );
769
+ }
770
+ } else {
771
+ // TODO: implement
772
+ }
773
+ llvm_unreachable (" code completion expression not implemented" );
774
+ return nullptr ;
775
+ }
776
+
650
777
Expr *ASTGen::generate (const UnknownExprSyntax &Expr, const SourceLoc Loc) {
651
778
if (Expr.getNumChildren () == 1 && Expr.getChild (0 )->isToken ()) {
652
779
Syntax Token = *Expr.getChild (0 );
0 commit comments