Skip to content

[Syntax] return-statement, integer-literal-expression, child caching #7706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CODE_OWNERS.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ D: Swift standard library

N: David Farler
E: [email protected]
D: Markup, Swift Linux port
D: Markup, lib/Syntax, Swift Linux port

N: Doug Gregor
E: [email protected]
Expand Down
8 changes: 8 additions & 0 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,14 @@ class NumberLiteralExpr : public LiteralExpr {
return DigitsLoc;
}

SourceLoc getMinusLoc() const {
return MinusLoc;
}

SourceLoc getDigitsLoc() const {
return DigitsLoc;
}

static bool classof(const Expr *E) {
return E->getKind() >= ExprKind::First_NumberLiteralExpr
&& E->getKind() <= ExprKind::Last_NumberLiteralExpr;
Expand Down
47 changes: 40 additions & 7 deletions include/swift/Syntax/DeclSyntax.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
namespace swift {
namespace syntax {

#pragma mark declaration Data

class DeclSyntaxData : public SyntaxData {
protected:
DeclSyntaxData(RC<RawSyntax> Raw, const SyntaxData *Parent = nullptr,
Expand All @@ -40,6 +42,8 @@ class DeclSyntaxData : public SyntaxData {
static bool classof(const SyntaxData *S) { return S->isDecl(); }
};

#pragma mark declaration API

class DeclSyntax : public Syntax {
friend class Syntax;
using DataType = DeclSyntaxData;
Expand All @@ -50,6 +54,39 @@ class DeclSyntax : public Syntax {
static bool classof(const SyntaxData *S) { return S->isDecl(); }
};

#pragma mark - unknown-declaration Data

class UnknownDeclSyntaxData : public DeclSyntaxData {
UnknownDeclSyntaxData(RC<RawSyntax> Raw, const SyntaxData *Parent = nullptr,
CursorIndex IndexInParent = 0);
public:
static RC<UnknownDeclSyntaxData> make(RC<RawSyntax> Raw,
const SyntaxData *Parent = nullptr,
CursorIndex IndexInParent = 0);

static bool classof(const SyntaxData *S) {
return S->getKind() == SyntaxKind::UnknownDecl;
}
};

#pragma mark - unknown-declaration API

class UnknownDeclSyntax : public DeclSyntax {
friend class SyntaxData;
friend class UnknownStmtSyntaxData;
friend class LegacyASTTransformer;

using DataType = UnknownDeclSyntaxData;

UnknownDeclSyntax(const RC<SyntaxData> Root,
const UnknownDeclSyntaxData *Data);

public:
static bool classof(const Syntax *S) {
return S->getKind() == SyntaxKind::UnknownDecl;
}
};

#pragma mark declaration-members Data

class DeclMembersSyntaxData final : public SyntaxData {
Expand Down Expand Up @@ -85,11 +122,7 @@ class DeclMembersSyntax final : public Syntax {
DeclMembersSyntax(RC<SyntaxData> Root,
const DeclMembersSyntaxData *Data);
public:
static DeclMembersSyntax make(const RC<SyntaxData> Root,
const DeclMembersSyntaxData *Data);
static DeclMembersSyntax makeBlank();

static bool classof(const SyntaxData *S) {
static bool classof(const Syntax *S) {
return S->getKind() == SyntaxKind::DeclMembers;
}
};
Expand Down Expand Up @@ -213,8 +246,8 @@ class StructDeclSyntax final : public DeclSyntax {
/// Return a StructDeclSyntax with the given right brace '}' token.
StructDeclSyntax withRightBrace(RC<TokenSyntax> NewRightBrace) const;

static bool classof(const SyntaxData *Data) {
return Data->getKind() == SyntaxKind::StructDecl;
static bool classof(const Syntax *S) {
return S->getKind() == SyntaxKind::StructDecl;
}
};

Expand Down
150 changes: 150 additions & 0 deletions include/swift/Syntax/ExprSyntax.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
//===--- ExprSyntax.h - Swift Expression Syntax Interface --------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines the interface for expresion-specific syntax nodes,
// such as
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_SYNTAX_EXPRSYNTAX_H
#define SWIFT_SYNTAX_EXPRSYNTAX_H

#include "swift/Syntax/RawSyntax.h"
#include "swift/Syntax/References.h"
#include "swift/Syntax/Syntax.h"
#include "swift/Syntax/SyntaxData.h"
#include "swift/Syntax/TokenSyntax.h"

using llvm::Optional;

namespace swift {
namespace syntax {

class ExprSyntaxData : public SyntaxData {
protected:
ExprSyntaxData(RC<RawSyntax> Raw, const SyntaxData *Parent = nullptr,
CursorIndex IndexInParent = 0)
: SyntaxData(Raw, Parent, IndexInParent) {
assert(Raw->isExpr());
}
public:
static RC<ExprSyntaxData> make(RC<RawSyntax> Raw,
const SyntaxData *Parent = nullptr,
CursorIndex IndexInParent = 0);
static RC<ExprSyntaxData> makeBlank();
static bool classof(const SyntaxData *S) {
return S->isExpr();
}
};

class ExprSyntax : public Syntax {
public:
using DataType = ExprSyntaxData;

ExprSyntax(const RC<SyntaxData> Root, const ExprSyntaxData *Data);
static bool classof(const Syntax *S) {
return S->isExpr();
}
};

#pragma mark - unknown-expression Data

class UnknownExprSyntaxData : public ExprSyntaxData {
UnknownExprSyntaxData(RC<RawSyntax> Raw, const SyntaxData *Parent = nullptr,
CursorIndex IndexInParent = 0);
public:
static RC<UnknownExprSyntaxData> make(RC<RawSyntax> Raw,
const SyntaxData *Parent = nullptr,
CursorIndex IndexInParent = 0);

static bool classof(const SyntaxData *S) {
return S->getKind() == SyntaxKind::UnknownExpr;
}
};

#pragma mark - unknown-expression API

class UnknownExprSyntax : public ExprSyntax {
friend class SyntaxData;
friend class UnknownExprSyntaxData;
friend class LegacyASTTransformer;

using DataType = UnknownExprSyntaxData;

UnknownExprSyntax(const RC<SyntaxData> Root,
const UnknownExprSyntaxData *Data);

public:
static bool classof(const Syntax *S) {
return S->getKind() == SyntaxKind::UnknownExpr;
}
};

#pragma mark - integer-literal-expression Data

class IntegerLiteralExprSyntaxData : public ExprSyntaxData {
friend struct SyntaxFactory;
friend class SyntaxData;

IntegerLiteralExprSyntaxData(RC<RawSyntax> Raw,
const SyntaxData *Parent = nullptr,
CursorIndex IndexInParent = 0);
static RC<IntegerLiteralExprSyntaxData> make(RC<RawSyntax> Raw,
const SyntaxData *Parent = nullptr,
CursorIndex IndexInParent = 0);
static RC<IntegerLiteralExprSyntaxData> makeBlank();
public:
static bool classof(const SyntaxData *S) {
return S->getKind() == SyntaxKind::IntegerLiteralExpr;
}
};

#pragma mark - integer-literal-expression API

class IntegerLiteralExprSyntax : public ExprSyntax {
using DataType = IntegerLiteralExprSyntaxData;
friend struct SyntaxFactory;
friend class SyntaxData;
friend class IntegerLiteralExprSyntaxData;

IntegerLiteralExprSyntax(const RC<SyntaxData> Root,
const IntegerLiteralExprSyntaxData *Data);

enum class Cursor : CursorIndex {
Sign,
Digits
};

public:

/// Get the '+' or '-' associated with this integer literal expression.
RC<TokenSyntax> getSign() const;

/// Return a new IntegerLiteralExprSyntax with the given '+' or '-' sign.
IntegerLiteralExprSyntax withSign(RC<TokenSyntax> NewSign) const;

/// Return the string of digits comprising the number part of the integer
/// literal expression.
RC<TokenSyntax> getDigits() const;

/// Return a new IntegerLiteralExprSyntax with the given string of digits.
IntegerLiteralExprSyntax withDigits(RC<TokenSyntax> NewDigits) const;

static bool classof(const Syntax *S) {
return S->getKind() == SyntaxKind::IntegerLiteralExpr;
}
};

} // end namespace syntax
} // end namespace swift

#endif // SWIFT_SYNTAX_EXPRSYNTAX_H
Loading