Files
swift-mirror/include/swift/Syntax/SyntaxFactory.h.gyb
Josh Soref 871634b9f3 Spelling include (#42616)
* spelling: accessible

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: are

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: assume

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: attempt

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: children

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: convenience

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: creation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: default

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: dereference

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: deserialization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: embedded

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: enriched

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: excluding

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: for

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: global

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: guarantee

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialize

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: label

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: lifting

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: mangled

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: metadata

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: minimum

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: offset

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: only

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: otherwise

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: output

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: overall

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameter

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: passed

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: performance

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: referenced

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: standard

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: syntax

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: that

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: trivia

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: truncate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: undesirable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: uniformly

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: uninitialized

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: value

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: verification

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-25 09:00:59 -07:00

192 lines
5.6 KiB
C++

%{
from gyb_syntax_support import *
# -*- mode: C++ -*-
# Ignore the following admonition; it applies to the resulting .h file only
}%
//// Automatically Generated From SyntaxFactory.h.gyb.
//// Do Not Edit Directly!
//===------------- SyntaxFactory.h - Syntax Factory definition ------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SYNTAX_FACTORY_H
#define SWIFT_SYNTAX_FACTORY_H
#include "swift/Syntax/SyntaxNodes.h"
#include "swift/Syntax/Trivia.h"
#include "llvm/ADT/ArrayRef.h"
#include <vector>
namespace swift {
namespace syntax {
class SyntaxArena;
/// The Syntax factory - the one-stop shop for making new Syntax nodes.
class SyntaxFactory {
RC<SyntaxArena> Arena;
public:
explicit SyntaxFactory(const RC<SyntaxArena> &Arena) : Arena(Arena) {}
/// Make any kind of token.
TokenSyntax makeToken(tok Kind,
StringRef Text,
StringRef LeadingTrivia,
StringRef TrailingTrivia,
SourcePresence Presence
);
/// Collect a list of tokens into a piece of "unknown" syntax.
UnknownSyntax makeUnknownSyntax(llvm::ArrayRef<TokenSyntax> Tokens);
Optional<Syntax> createSyntax(
SyntaxKind Kind,
llvm::ArrayRef<Syntax> Elements
);
const RawSyntax *createRaw(
SyntaxKind Kind,
llvm::ArrayRef<const RawSyntax *> Elements
);
/// Count the number of children for a given syntax node kind,
/// returning a pair of minimum and maximum count of children. The gap
/// between these two numbers is the number of optional children.
static std::pair<unsigned, unsigned> countChildren(SyntaxKind Kind);
Syntax makeBlankCollectionSyntax(SyntaxKind Kind);
% for node in SYNTAX_NODES:
% if node.children:
% child_params = []
% for child in node.children:
% param_type = child.type_name
% if child.is_optional:
% param_type = "llvm::Optional<%s>" % param_type
% end
% child_params.append("%s %s" % (param_type, child.name))
% end
% child_params = ', '.join(child_params)
${node.name} make${node.syntax_kind}(${child_params});
% elif node.is_syntax_collection():
${node.name} make${node.syntax_kind}(
const std::vector<${node.collection_element_type}> &elts
);
% end
${node.name} makeBlank${node.syntax_kind}();
% end
% for token in SYNTAX_TOKENS:
% if token.is_keyword:
TokenSyntax make${token.name}Keyword(
StringRef LeadingTrivia,
StringRef TrailingTrivi
);
% elif token.text:
TokenSyntax make${token.name}Token(
StringRef LeadingTrivia,
StringRef TrailingTrivia
);
% else:
TokenSyntax make${token.name}(
StringRef Text,
StringRef LeadingTrivia, StringRef TrailingTrivia
);
% end
% end
#pragma mark - Convenience APIs
TupleTypeSyntax makeVoidTupleType();
/// Creates an labelled TupleTypeElementSyntax with the provided label,
/// colon, type and optional trailing comma.
TupleTypeElementSyntax makeTupleTypeElement(
llvm::Optional<TokenSyntax> Label,
llvm::Optional<TokenSyntax> Colon, TypeSyntax Type,
llvm::Optional<TokenSyntax> TrailingComma
);
/// Creates an unlabelled TupleTypeElementSyntax with the provided type and
/// optional trailing comma.
TupleTypeElementSyntax
makeTupleTypeElement(
TypeSyntax Type,
llvm::Optional<TokenSyntax> TrailingComma
);
/// Creates a TypeIdentifierSyntax with the provided name and leading/trailing
/// trivia.
TypeSyntax makeTypeIdentifier(
StringRef TypeName,
StringRef LeadingTrivia, StringRef TrailingTrivia
);
/// Creates a GenericParameterSyntax with no inheritance clause and an
/// optional trailing comma.
GenericParameterSyntax
makeGenericParameter(
TokenSyntax Name,
llvm::Optional<TokenSyntax> TrailingComma
);
/// Creates a TypeIdentifierSyntax for the `Any` type.
TypeSyntax makeAnyTypeIdentifier(
StringRef LeadingTrivia,
StringRef TrailingTrivia
);
/// Creates a TypeIdentifierSyntax for the `Self` type.
TypeSyntax makeSelfTypeIdentifier(
StringRef LeadingTrivia,
StringRef TrailingTrivia
);
/// Creates a TokenSyntax for the `Type` identifier.
TokenSyntax makeTypeToken(
StringRef LeadingTrivia,
StringRef TrailingTrivia
);
/// Creates a TokenSyntax for the `Protocol` identifier.
TokenSyntax makeProtocolToken(
StringRef LeadingTrivia,
StringRef TrailingTrivia
);
/// Creates an `==` operator token.
TokenSyntax makeEqualityOperator(
StringRef LeadingTrivia,
StringRef TrailingTrivia
);
/// Whether a raw node kind `MemberKind` can serve as a member in a syntax
/// collection of the given syntax collection kind.
static bool canServeAsCollectionMemberRaw(SyntaxKind CollectionKind,
SyntaxKind MemberKind);
/// Whether a raw node `Member` can serve as a member in a syntax collection
/// of the given syntax collection kind.
static bool canServeAsCollectionMemberRaw(SyntaxKind CollectionKind,
const RawSyntax *Member);
/// Whether a node `Member` can serve as a member in a syntax collection of
/// the given syntax collection kind.
static bool canServeAsCollectionMember(SyntaxKind CollectionKind, Syntax Member);
};
}
}
#endif // SWIFT_SYNTAX_FACTORY_H