|
| 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