Skip to content

Commit fa50dc5

Browse files
authored
Merge pull request #7706 from bitjammer/sr-4010-return-statement-syntax
[Syntax] return-statement, integer-literal-expression, child caching
2 parents ab0e817 + 19ed1dd commit fa50dc5

31 files changed

+1484
-353
lines changed

CODE_OWNERS.TXT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ D: Swift standard library
1313

1414
N: David Farler
1515
16-
D: Markup, Swift Linux port
16+
D: Markup, lib/Syntax, Swift Linux port
1717

1818
N: Doug Gregor
1919

include/swift/AST/Expr.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,14 @@ class NumberLiteralExpr : public LiteralExpr {
840840
return DigitsLoc;
841841
}
842842

843+
SourceLoc getMinusLoc() const {
844+
return MinusLoc;
845+
}
846+
847+
SourceLoc getDigitsLoc() const {
848+
return DigitsLoc;
849+
}
850+
843851
static bool classof(const Expr *E) {
844852
return E->getKind() >= ExprKind::First_NumberLiteralExpr
845853
&& E->getKind() <= ExprKind::Last_NumberLiteralExpr;

include/swift/Syntax/DeclSyntax.h

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
namespace swift {
3232
namespace syntax {
3333

34+
#pragma mark declaration Data
35+
3436
class DeclSyntaxData : public SyntaxData {
3537
protected:
3638
DeclSyntaxData(RC<RawSyntax> Raw, const SyntaxData *Parent = nullptr,
@@ -40,6 +42,8 @@ class DeclSyntaxData : public SyntaxData {
4042
static bool classof(const SyntaxData *S) { return S->isDecl(); }
4143
};
4244

45+
#pragma mark declaration API
46+
4347
class DeclSyntax : public Syntax {
4448
friend class Syntax;
4549
using DataType = DeclSyntaxData;
@@ -50,6 +54,39 @@ class DeclSyntax : public Syntax {
5054
static bool classof(const SyntaxData *S) { return S->isDecl(); }
5155
};
5256

57+
#pragma mark - unknown-declaration Data
58+
59+
class UnknownDeclSyntaxData : public DeclSyntaxData {
60+
UnknownDeclSyntaxData(RC<RawSyntax> Raw, const SyntaxData *Parent = nullptr,
61+
CursorIndex IndexInParent = 0);
62+
public:
63+
static RC<UnknownDeclSyntaxData> make(RC<RawSyntax> Raw,
64+
const SyntaxData *Parent = nullptr,
65+
CursorIndex IndexInParent = 0);
66+
67+
static bool classof(const SyntaxData *S) {
68+
return S->getKind() == SyntaxKind::UnknownDecl;
69+
}
70+
};
71+
72+
#pragma mark - unknown-declaration API
73+
74+
class UnknownDeclSyntax : public DeclSyntax {
75+
friend class SyntaxData;
76+
friend class UnknownStmtSyntaxData;
77+
friend class LegacyASTTransformer;
78+
79+
using DataType = UnknownDeclSyntaxData;
80+
81+
UnknownDeclSyntax(const RC<SyntaxData> Root,
82+
const UnknownDeclSyntaxData *Data);
83+
84+
public:
85+
static bool classof(const Syntax *S) {
86+
return S->getKind() == SyntaxKind::UnknownDecl;
87+
}
88+
};
89+
5390
#pragma mark declaration-members Data
5491

5592
class DeclMembersSyntaxData final : public SyntaxData {
@@ -85,11 +122,7 @@ class DeclMembersSyntax final : public Syntax {
85122
DeclMembersSyntax(RC<SyntaxData> Root,
86123
const DeclMembersSyntaxData *Data);
87124
public:
88-
static DeclMembersSyntax make(const RC<SyntaxData> Root,
89-
const DeclMembersSyntaxData *Data);
90-
static DeclMembersSyntax makeBlank();
91-
92-
static bool classof(const SyntaxData *S) {
125+
static bool classof(const Syntax *S) {
93126
return S->getKind() == SyntaxKind::DeclMembers;
94127
}
95128
};
@@ -213,8 +246,8 @@ class StructDeclSyntax final : public DeclSyntax {
213246
/// Return a StructDeclSyntax with the given right brace '}' token.
214247
StructDeclSyntax withRightBrace(RC<TokenSyntax> NewRightBrace) const;
215248

216-
static bool classof(const SyntaxData *Data) {
217-
return Data->getKind() == SyntaxKind::StructDecl;
249+
static bool classof(const Syntax *S) {
250+
return S->getKind() == SyntaxKind::StructDecl;
218251
}
219252
};
220253

include/swift/Syntax/ExprSyntax.h

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
//===--- ExprSyntax.h - Swift Expression Syntax Interface --------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines the interface for expresion-specific syntax nodes,
14+
// such as
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef SWIFT_SYNTAX_EXPRSYNTAX_H
19+
#define SWIFT_SYNTAX_EXPRSYNTAX_H
20+
21+
#include "swift/Syntax/RawSyntax.h"
22+
#include "swift/Syntax/References.h"
23+
#include "swift/Syntax/Syntax.h"
24+
#include "swift/Syntax/SyntaxData.h"
25+
#include "swift/Syntax/TokenSyntax.h"
26+
27+
using llvm::Optional;
28+
29+
namespace swift {
30+
namespace syntax {
31+
32+
class ExprSyntaxData : public SyntaxData {
33+
protected:
34+
ExprSyntaxData(RC<RawSyntax> Raw, const SyntaxData *Parent = nullptr,
35+
CursorIndex IndexInParent = 0)
36+
: SyntaxData(Raw, Parent, IndexInParent) {
37+
assert(Raw->isExpr());
38+
}
39+
public:
40+
static RC<ExprSyntaxData> make(RC<RawSyntax> Raw,
41+
const SyntaxData *Parent = nullptr,
42+
CursorIndex IndexInParent = 0);
43+
static RC<ExprSyntaxData> makeBlank();
44+
static bool classof(const SyntaxData *S) {
45+
return S->isExpr();
46+
}
47+
};
48+
49+
class ExprSyntax : public Syntax {
50+
public:
51+
using DataType = ExprSyntaxData;
52+
53+
ExprSyntax(const RC<SyntaxData> Root, const ExprSyntaxData *Data);
54+
static bool classof(const Syntax *S) {
55+
return S->isExpr();
56+
}
57+
};
58+
59+
#pragma mark - unknown-expression Data
60+
61+
class UnknownExprSyntaxData : public ExprSyntaxData {
62+
UnknownExprSyntaxData(RC<RawSyntax> Raw, const SyntaxData *Parent = nullptr,
63+
CursorIndex IndexInParent = 0);
64+
public:
65+
static RC<UnknownExprSyntaxData> make(RC<RawSyntax> Raw,
66+
const SyntaxData *Parent = nullptr,
67+
CursorIndex IndexInParent = 0);
68+
69+
static bool classof(const SyntaxData *S) {
70+
return S->getKind() == SyntaxKind::UnknownExpr;
71+
}
72+
};
73+
74+
#pragma mark - unknown-expression API
75+
76+
class UnknownExprSyntax : public ExprSyntax {
77+
friend class SyntaxData;
78+
friend class UnknownExprSyntaxData;
79+
friend class LegacyASTTransformer;
80+
81+
using DataType = UnknownExprSyntaxData;
82+
83+
UnknownExprSyntax(const RC<SyntaxData> Root,
84+
const UnknownExprSyntaxData *Data);
85+
86+
public:
87+
static bool classof(const Syntax *S) {
88+
return S->getKind() == SyntaxKind::UnknownExpr;
89+
}
90+
};
91+
92+
#pragma mark - integer-literal-expression Data
93+
94+
class IntegerLiteralExprSyntaxData : public ExprSyntaxData {
95+
friend struct SyntaxFactory;
96+
friend class SyntaxData;
97+
98+
IntegerLiteralExprSyntaxData(RC<RawSyntax> Raw,
99+
const SyntaxData *Parent = nullptr,
100+
CursorIndex IndexInParent = 0);
101+
static RC<IntegerLiteralExprSyntaxData> make(RC<RawSyntax> Raw,
102+
const SyntaxData *Parent = nullptr,
103+
CursorIndex IndexInParent = 0);
104+
static RC<IntegerLiteralExprSyntaxData> makeBlank();
105+
public:
106+
static bool classof(const SyntaxData *S) {
107+
return S->getKind() == SyntaxKind::IntegerLiteralExpr;
108+
}
109+
};
110+
111+
#pragma mark - integer-literal-expression API
112+
113+
class IntegerLiteralExprSyntax : public ExprSyntax {
114+
using DataType = IntegerLiteralExprSyntaxData;
115+
friend struct SyntaxFactory;
116+
friend class SyntaxData;
117+
friend class IntegerLiteralExprSyntaxData;
118+
119+
IntegerLiteralExprSyntax(const RC<SyntaxData> Root,
120+
const IntegerLiteralExprSyntaxData *Data);
121+
122+
enum class Cursor : CursorIndex {
123+
Sign,
124+
Digits
125+
};
126+
127+
public:
128+
129+
/// Get the '+' or '-' associated with this integer literal expression.
130+
RC<TokenSyntax> getSign() const;
131+
132+
/// Return a new IntegerLiteralExprSyntax with the given '+' or '-' sign.
133+
IntegerLiteralExprSyntax withSign(RC<TokenSyntax> NewSign) const;
134+
135+
/// Return the string of digits comprising the number part of the integer
136+
/// literal expression.
137+
RC<TokenSyntax> getDigits() const;
138+
139+
/// Return a new IntegerLiteralExprSyntax with the given string of digits.
140+
IntegerLiteralExprSyntax withDigits(RC<TokenSyntax> NewDigits) const;
141+
142+
static bool classof(const Syntax *S) {
143+
return S->getKind() == SyntaxKind::IntegerLiteralExpr;
144+
}
145+
};
146+
147+
} // end namespace syntax
148+
} // end namespace swift
149+
150+
#endif // SWIFT_SYNTAX_EXPRSYNTAX_H

0 commit comments

Comments
 (0)