mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Test shadowed variable of same type Fully type check caller side macro expansion Skip macro default arg caller side expr at decl primary Test macro expand more complex expressions Set synthesized expression as implicit Add test case for with argument, not compiling currently Test with swiftinterface Always use the string representation of the default argument Now works across module boundary Check works for multiple files Make default argument expression work in single file Use expected-error Disallow expression macro as default argument Using as a sub expression in default argument still allowed as expression macros behave the same as built-in magic literals
102 lines
3.1 KiB
C++
102 lines
3.1 KiB
C++
//===--- DefaultArgumentKind.h - Default Argument Kind Enum -----*- 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 DefaultArgumentKind enumeration.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_DEFAULTARGUMENTKIND_H
|
|
#define SWIFT_DEFAULTARGUMENTKIND_H
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
namespace llvm {
|
|
class StringRef;
|
|
}
|
|
|
|
namespace swift {
|
|
|
|
class Expr;
|
|
|
|
/// Describes the kind of default argument a tuple pattern element has.
|
|
enum class DefaultArgumentKind : uint8_t {
|
|
/// No default argument.
|
|
None,
|
|
/// A normal default argument.
|
|
Normal,
|
|
/// The default argument is inherited from the corresponding argument of the
|
|
/// overridden declaration.
|
|
Inherited,
|
|
/// The "nil" literal.
|
|
NilLiteral,
|
|
/// An empty array literal.
|
|
EmptyArray,
|
|
/// An empty dictionary literal.
|
|
EmptyDictionary,
|
|
/// A reference to the stored property. This is a special default argument
|
|
/// kind for the synthesized memberwise constructor to emit a call to the
|
|
/// property's initializer.
|
|
StoredProperty,
|
|
// Magic identifier literals expanded at the call site:
|
|
#define MAGIC_IDENTIFIER(NAME, STRING, SYNTAX_KIND) NAME,
|
|
#include "swift/AST/MagicIdentifierKinds.def"
|
|
/// An expression macro.
|
|
ExpressionMacro
|
|
};
|
|
enum { NumDefaultArgumentKindBits = 4 };
|
|
|
|
/// Determine the kind of a default argument given a parsed expression that has
|
|
/// not yet been type-checked.
|
|
/// FIXME: Requestify/internalize the computation of the default arg expr and its kind (given a parsed expr) once the old parser no longer needs this.
|
|
DefaultArgumentKind getDefaultArgKind(Expr *init);
|
|
|
|
struct ArgumentAttrs {
|
|
DefaultArgumentKind argumentKind;
|
|
bool isUnavailableInSwift = false;
|
|
llvm::StringRef CXXOptionsEnumName = "";
|
|
|
|
ArgumentAttrs(DefaultArgumentKind argumentKind,
|
|
bool isUnavailableInSwift = false,
|
|
llvm::StringRef CXXOptionsEnumName = "")
|
|
: argumentKind(argumentKind), isUnavailableInSwift(isUnavailableInSwift),
|
|
CXXOptionsEnumName(CXXOptionsEnumName) {}
|
|
|
|
bool operator !=(const DefaultArgumentKind &rhs) const {
|
|
return argumentKind != rhs;
|
|
}
|
|
|
|
bool operator==(const DefaultArgumentKind &rhs) const {
|
|
return argumentKind == rhs;
|
|
}
|
|
|
|
bool hasDefaultArg() const {
|
|
return argumentKind != DefaultArgumentKind::None;
|
|
}
|
|
|
|
bool hasAlternateCXXOptionsEnumName() const {
|
|
return !CXXOptionsEnumName.empty() && isUnavailableInSwift;
|
|
}
|
|
|
|
llvm::StringRef getAlternateCXXOptionsEnumName() const {
|
|
assert(hasAlternateCXXOptionsEnumName() &&
|
|
"Expected a C++ Options type for C++-Interop but found none.");
|
|
return CXXOptionsEnumName;
|
|
}
|
|
};
|
|
|
|
} // end namespace swift
|
|
|
|
#endif // LLVM_SWIFT_DEFAULTARGUMENTKIND_H
|
|
|