Files
swift-mirror/include/swift/AST/DeclNodes.def
Joe Groff aeeda4ee12 Parser: Parse operator decls.
At the top level, if 'operator' is followed by 'infix', 'prefix', or 'postfix', consider it a contextual keyword, and parse an operator decl following it that looks like:

  operator {infix|postfix|prefix} <+> {
    attributes…
  }

Prefix and postfix operator decls currently admit no attributes. Infix operators have 'associativity {left|right|none}' and 'precedence <int>' attributes.

This patch implements parsing for operator declarations but does not yet attach the declared attributes to func decls for the operators.

Swift SVN r4596
2013-04-03 23:30:50 +00:00

95 lines
3.1 KiB
C++

//===-- DeclNodes.def - Swift Declaration AST Metaprogramming -*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines macros used for macro-metaprogramming with declarations.
//
//===----------------------------------------------------------------------===//
/// DECL(Id, Parent)
/// If the declaration node is not abstract, its enumerator value is
/// DeclKind::Id. The node's class name is Id##Decl, and the name of
/// its base class (in the Decl hierarchy) is Parent.
/// An abstract declaration node is an abstract base class in the hierarchy;
/// it is never a most-derived type, and it does not have an enumerator in
/// DeclKind.
///
/// Most metaprograms do not care about abstract declarations, so the default
/// is to ignore them.
#ifndef ABSTRACT_DECL
#define ABSTRACT_DECL(Id, Parent)
#endif
/// VALUE_DECL(Id, Parent)
/// Used for subclasses of ValueDecl. The default behavior is to do
/// the same as for Decl.
#ifndef VALUE_DECL
#define VALUE_DECL(Id, Parent) DECL(Id, Parent)
#endif
/// OPERATOR_DECL(Id, Parent)
/// Used for subclasses of OperatorDecl. The default behavior is to do
/// the same as for Decl.
#ifndef OPERATOR_DECL
#define OPERATOR_DECL(Id, Parent) DECL(Id, Parent)
#endif
/// NOMINAL_TYPE_DECL(Id, Parent)
/// Used for subclasses of NominalTypeDecl. The default behavior is
/// to do the same as for ValueDecl.
#ifndef NOMINAL_TYPE_DECL
#define NOMINAL_TYPE_DECL(Id, Parent) VALUE_DECL(Id, Parent)
#endif
/// A convenience for determining the range of declarations. These will always
/// appear immediately after the last member.
#ifndef DECL_RANGE
#define DECL_RANGE(Id, First, Last)
#endif
DECL(Import, Decl)
DECL(Extension, Decl)
DECL(PatternBinding, Decl)
DECL(TopLevelCode, Decl)
ABSTRACT_DECL(Operator, Decl)
OPERATOR_DECL(InfixOperator, Decl)
OPERATOR_DECL(PrefixOperator, Decl)
OPERATOR_DECL(PostfixOperator, Decl)
DECL_RANGE(Operator, InfixOperator, PostfixOperator)
ABSTRACT_DECL(Value, Decl)
ABSTRACT_DECL(Type, Decl)
VALUE_DECL(TypeAlias, TypeDecl)
ABSTRACT_DECL(NominalType, TypeDecl)
NOMINAL_TYPE_DECL(OneOf, NominalTypeDecl)
NOMINAL_TYPE_DECL(Struct, NominalTypeDecl)
NOMINAL_TYPE_DECL(Class, NominalTypeDecl)
NOMINAL_TYPE_DECL(Protocol, NominalTypeDecl)
DECL_RANGE(NominalType, OneOf, Protocol)
DECL_RANGE(Type, TypeAlias, Protocol)
VALUE_DECL(Var, ValueDecl)
VALUE_DECL(Func, ValueDecl)
VALUE_DECL(OneOfElement, ValueDecl)
VALUE_DECL(Subscript, ValueDecl)
VALUE_DECL(Constructor, ValueDecl)
VALUE_DECL(Destructor, ValueDecl)
DECL_RANGE(Value, TypeAlias, Constructor)
#undef NOMINAL_TYPE_DECL
#undef VALUE_DECL
#undef DECL_RANGE
#undef ABSTRACT_DECL
#undef DECL