mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Replace Attr.def with a gyb file that reads from swift-syntax to automatically generate the attribute nodes. For now, only the Swift attributes have been migrated. SIL attributes can be defined manually in Attr.def.gyb. To add new Swift attributes, a paired pull request to swift-syntax is now necessary.
133 lines
3.9 KiB
C++
133 lines
3.9 KiB
C++
%{
|
|
# -*- mode: C++ -*-
|
|
from gyb_syntax_support import *
|
|
from gyb_syntax_support.AttributeKinds import *
|
|
# Ignore the following admonition; it applies to the resulting .def file only
|
|
}%
|
|
//// Automatically Generated From Attr.def.gyb.
|
|
//// Do Not Edit Directly!
|
|
//===--- Attr.def - Swift Attributes Metaprogramming ------------*- 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 macros used for macro-metaprogramming with attributes.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef DECL_ATTR
|
|
#define DECL_ATTR(SPELLING, CLASS, OPTIONS, CODE)
|
|
#endif
|
|
|
|
#ifndef CONTEXTUAL_DECL_ATTR
|
|
#define CONTEXTUAL_DECL_ATTR(SPELLING, CLASS, OPTIONS, CODE) \
|
|
DECL_ATTR(SPELLING, CLASS, OPTIONS, CODE)
|
|
#endif
|
|
|
|
#ifndef SIMPLE_DECL_ATTR
|
|
#define SIMPLE_DECL_ATTR(X, CLASS, OPTIONS, CODE) \
|
|
DECL_ATTR(X, CLASS, OPTIONS, CODE)
|
|
#endif
|
|
|
|
#ifndef CONTEXTUAL_SIMPLE_DECL_ATTR
|
|
#define CONTEXTUAL_SIMPLE_DECL_ATTR(X, CLASS, OPTIONS, CODE) \
|
|
SIMPLE_DECL_ATTR(X, CLASS, OPTIONS, CODE)
|
|
#endif
|
|
|
|
#ifndef DECL_ATTR_ALIAS
|
|
#define DECL_ATTR_ALIAS(SPELLING, CLASS)
|
|
#endif
|
|
|
|
#ifndef CONTEXTUAL_DECL_ATTR_ALIAS
|
|
#define CONTEXTUAL_DECL_ATTR_ALIAS(SPELLING, CLASS) \
|
|
DECL_ATTR_ALIAS(SPELLING, CLASS)
|
|
#endif
|
|
|
|
#ifndef TYPE_ATTR
|
|
#define TYPE_ATTR(X)
|
|
#endif
|
|
|
|
// Type attributes
|
|
% for attr in TYPE_ATTR_KINDS:
|
|
TYPE_ATTR(${attr.name})
|
|
% end
|
|
|
|
// SIL-specific attributes
|
|
TYPE_ATTR(block_storage)
|
|
TYPE_ATTR(box)
|
|
TYPE_ATTR(dynamic_self)
|
|
#define REF_STORAGE(Name, name, ...) TYPE_ATTR(sil_##name)
|
|
#include "swift/AST/ReferenceStorage.def"
|
|
TYPE_ATTR(error)
|
|
TYPE_ATTR(out)
|
|
TYPE_ATTR(in)
|
|
TYPE_ATTR(inout)
|
|
TYPE_ATTR(inout_aliasable)
|
|
TYPE_ATTR(in_guaranteed)
|
|
TYPE_ATTR(in_constant)
|
|
TYPE_ATTR(owned)
|
|
TYPE_ATTR(unowned_inner_pointer)
|
|
TYPE_ATTR(guaranteed)
|
|
TYPE_ATTR(autoreleased)
|
|
TYPE_ATTR(callee_owned)
|
|
TYPE_ATTR(callee_guaranteed)
|
|
TYPE_ATTR(objc_metatype)
|
|
TYPE_ATTR(opened)
|
|
TYPE_ATTR(pseudogeneric)
|
|
TYPE_ATTR(yields)
|
|
TYPE_ATTR(yield_once)
|
|
TYPE_ATTR(yield_many)
|
|
TYPE_ATTR(captures_generics)
|
|
// Used at the SIL level to mark a type as moveOnly.
|
|
TYPE_ATTR(moveOnly)
|
|
|
|
// SIL metatype attributes.
|
|
TYPE_ATTR(thin)
|
|
TYPE_ATTR(thick)
|
|
|
|
// Declaration Attributes and Modifers
|
|
// To add a new entry here, update https://github.com/apple/swift-syntax
|
|
% for attr in DECL_ATTR_KINDS + DECL_MODIFIER_KINDS + DEPRECATED_MODIFIER_KINDS:
|
|
% if type(attr) is ContextualDeclAttributeAlias:
|
|
CONTEXTUAL_DECL_ATTR_ALIAS(${attr.name}, ${attr.class_name})
|
|
% elif type(attr) is DeclAttributeAlias:
|
|
DECL_ATTR_ALIAS(${attr.name}, ${attr.class_name})
|
|
% elif type(attr) is ContextualSimpleDeclAttribute:
|
|
CONTEXTUAL_SIMPLE_DECL_ATTR(${attr.name}, ${attr.class_name},
|
|
${' | '.join(attr.options)},
|
|
${str(attr.code)})
|
|
% elif type(attr) is ContextualDeclAttribute:
|
|
CONTEXTUAL_DECL_ATTR(${attr.name}, ${attr.class_name},
|
|
${' | '.join(attr.options)},
|
|
${str(attr.code)})
|
|
% elif type(attr) is SimpleDeclAttribute:
|
|
SIMPLE_DECL_ATTR(${attr.name}, ${attr.class_name},
|
|
${' | '.join(attr.options)},
|
|
${str(attr.code)})
|
|
% elif type(attr) is DeclAttribute:
|
|
DECL_ATTR(${attr.name}, ${attr.class_name},
|
|
${' | '.join(attr.options)},
|
|
${str(attr.code)})
|
|
% elif type(attr) is BuiltinDeclModifier:
|
|
% # These are not actually decl attributes, ignore them.
|
|
% pass
|
|
% else:
|
|
% raise RuntimeError(f'Unhandled attribute class {type(attr)}')
|
|
% end
|
|
% end
|
|
|
|
#undef TYPE_ATTR
|
|
#undef DECL_ATTR_ALIAS
|
|
#undef CONTEXTUAL_DECL_ATTR_ALIAS
|
|
#undef SIMPLE_DECL_ATTR
|
|
#undef CONTEXTUAL_SIMPLE_DECL_ATTR
|
|
#undef DECL_ATTR
|
|
#undef CONTEXTUAL_DECL_ATTR
|